frnds ,i have a problem with this program..
i got the output but could anybody tell the reason.
class a{
a(){
System.out.println("Q");
}
}
Modify your class a to look something like:
class AClass {
private int aVariable;
public AClass() {
System.out.println("Constructing AClass.");
aVariable = 42;
}
public int getAVariable() { return aVariable; }
}
The modified class now has its own member data, and its constructor
has some work to do setting it. There is also a getter to return the
value of the data variable.
class b extends a{
b(){
System.out.println("W");
}
}
Same here:
class BClass extends AClass {
private double bVariable;
public BClass() {
System.out.println("Constructing BClass.");
bVariable = 123.0;
}
public double getBVariable() { return bVariable; }
}
class c extends b{
c(){
System.out.println("E");
}
}
And again:
class CClass extends BClass {
private String cVariable;
public CClass() {
System.out.println("Constructing CClass.");
cVariable = "Hello World!";
}
public String getCVariable() { return cVariable; }
}
class output{
public static void main(String [] args){
c Object =new c();
}
}
Now amend you main() method to look something like:
public static void main(String [] args){
CClass myCObject = new CClass();
System.out.println("myCObject.aVariable = " +
myCObject.getAVariable());
System.out.println("myCObject.bVariable = " +
myCObject.getBVariable());
System.out.println("myCObject.cVariable = " +
myCObject.getCVariable());
}
What do you expect the output to be from your modified program? What
values do you expect for myCObject.aVariable, myCObject.bVariable and
myCObject.cVariable? For each of those three values say where it was
set.
could anybody tell reason?
Now you should be able to tell yourself the reason.
rossum