Site Search:

Know how to read or write to object fields

Back OCAJP


Object fields can be set and get from inside and outside the class.


OCAJP>cat test.java 
public class test{
  tester t = new tester();
  int d = t.c; //read c and write d
}
class tester {
private int a = 1;  //write a
private int b = 2;  //write b
protected int c = a + b;  //read a, b and write c
}
OCAJP>javac test.java 

OCAJP>
Back OCAJP