1.What will be the Output of this program.
- public class Test1{
-
- Test1(int i){
-
- System.out.println("Test1 Constructor "+i);
-
- }
- }
- public class Test2{
-
- Test1 t1= new Test1(10);
-
- Test2(int i){
-
- System.out.println("Test2 Constructor "+i);
-
- }
- public static void main(String[] args) {
-
- Test2 t2= new Test2(5);
-
- }
- }
Click for Output
- Test1 Constructor 10
- Test1 Constructor 5
2.What will be the Output of this program.
- public class A{
-
- A(){
-
- System.out.println("A Class Constructor ");
-
- }
-
- }
- public class B extends A{
-
- B(){
-
- System.out.println("B Class Constructor ");
-
- }
- public static void main(String[] args) {
-
- B ob= new B();
-
- }
- }
Click for Output
- A Class Constructor
- B Class Constructor
3.What will be the Output of this program.
- public class A{
-
- A(){
- this(0);
- System.out.println("Hi ");
-
- }
-
- A(int x){
- this(0,0);
- System.out.println("Hello");
-
- }
-
- A(int x, int y){
-
- System.out.println("How are you");
-
- }
- public static void main(String[] args) {
-
- A ob= new A();
-
- }
- }
Click for Output