// main.java
public class main {
public static void main(String[] args ){
STD2 obj2=new STD2();
}
}
// STD.java
public class STD{
public STD(){
System.out.println("Works STD Constructor!");
}
}
// STD2.java
public class STD2 extends STD{
public STD2(){
System.out.println("Works STD2 Constructor!");
}
}
Si then the result will be:
C:\Users\vakho\Desktop>javac *.java
C:\Users\vakho\Desktop>java main
Works STD Constructor!
Works STD2 Constructor!
Questions:
1)Could I invoke(run) only STD2 Constructor here?... If i Cerate STD2 object, why STD Constuctor runs (Invokes)?
2) In C++, we could Write all the classes together, Could we make something like this in Java?
Edited by VakhoQ, 20 July 2011 - 06:40 AM.


Sign In
Create Account


Back to top









