I have modified the above code snippet, as follows
==================================================
class Base {
int i = 99;
private void amethod(){
System.out.println("Base.amethod()");
}
Base(){
amethod();
}
}
public class Derived extends Base{
int i = -1;
public static void main(
String argv[]){
Base b = new Derived();
//System.out.println(b.i);
//b.amethod(); // can't call the private method.....
}
public void amethod(){
System.out.println("Derived.amethod()");
}
Derived(){
amethod();
}
}
=================================================
Prints:
Base.amethod()
Derived.amethod()
=================================================
Here I am just creationg an object and its calling both the constructors in the base class as well as Derived class, and when I remove the constructor in the Derived class it just calls the aMethod and print both the statements. Can somebody explain why?
--Farooq