Can you call a constructor within a constructor?

Answer Posted / amit kumar gupta

yes we can call by super() or this();

public abstract class Class1{

public Class1(){
System.out.println("Class1");
}
}

public class Class2 extends Class1{

public Class2(String Name){
System.out.println("Name = " + Name);
}

public Class2(){
this("AMIT"); // use only one this or super
super();
}
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a switch statement and an if statement?

518


What are the 6 mandatory procedures for iso 9001?

532


Explain the difference between extends thread vs implements runnable in java?

542


How many bits are in a sentence?

588


What is string [] args?

561






What is math floor in java?

477


What is the purpose of object oriented programming?

540


Can inner class have constructor?

552


Is singleton a bad practice?

580


What is difference between wait and notify in java?

548


What is the importance of main method in Java?

577


What is class array in java?

515


If a class is declared without any access modifiers, where may the class be accessed in java programming?

662


Why we used break and continue statement in java?

563


What classes of exceptions may be thrown by a throw statement?

532