Java Reference
In-Depth Information
this.x = x;
this.y = y;
System.out.println (" In Test2(double x, double y) " );
}
// Three-arg constructor
Test2 (boolean b, double x, double y) {
super (b, 5);
flag = b;
System.out.println (
"In Test2(boolean b, double x, double y)");
}
}
The output of ConstructApp3 goes as:
First test2 object
In Test()
In Test(int j)
In Test1(boolean b)
In Test2(double x, double y)
Second test2 object
In Test()
In Test(int j)
In Test1(boolean b)
In Test1(boolean b, int j)
In Test2(boolean b, double x, double y)
This illustrates the different sequence of constructors invoked according to which
of the Test2 constructors we choose.
4.4 Abstract methods and classes
For some applications we might need a generic base class that we never actually
instantiate. Instead, we want always to use subclasses of that base class. That is,
the base class handles behavior that is common to all the subclasses but does not
contain enough data or behavior to be useful on its own. In a sense, the common
behavior has been “factored out” of the subclasses and moved to the common
base class.
Search WWH ::




Custom Search