0
constructor
classDemo2 { inta,b; Demo2(){ System.out.println("default constructor"); a=5;b=10; System.out.println("value of a = "+a); System.out.println("value of b = "+b); } classDemo1{ public static void main(String args[]) {Demo2 d2=newDemo2(); } }
2 Respostas
+ 1
the Constructor has to be the same name as the class. So class Demo2 constructor has to be called Demo2()
0
a constructor is called at the instance when an object is created.
there is semantic error in your program.
that is class and Demo2 should have space (class_class name).
And the closing parentheses of class Demo2..