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

Does substring create a new object?

519


What is difference between next () and nextline () in java?

521


Define inheritance with reference to java.

570


How can we achieve thread safety in java?

668


What is annotation in java?

563






What is the += operator called?

568


What is string data?

543


Is space a char?

517


What is the difference between this() and super() in java?

521


Define jre i.e. Java runtime environment?

563


What is the maximum size of a string in java?

536


What is a parameter in matrices?

527


what is the messsage u r going to get from an objectoriented programing?

1592


Can we inherit a class with private constructor?

556


Can we define a package statement after the import statement in java?

561