Can you have a constructor in abstract class?

Answer Posted / vinoth kumar

Yes,
we can define it in the abstract class itself.But it invoke
only by super() in sub class constructor.

Example:

abstract class AbsConstCheck{
AbsConstCheck(){
System.out.println("I AM WORKING AbsConstCheck");
}//some other methods declaration
}
class Sub extends AbsConstCheck{
sub(){
super();//calling abstract class constructor
System.out.println("I AM WORKING Sub");
}
}
class Main{
public static void main(String vin[]){
Sub s=new Sub();//calling sub,abstract class constructor
}
}

Output:

I AM WORKING AbsConstCheck
I AM WORKING Sub

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is it possible for two string objects with identical values not to be equal under the == operator?

616


How many types of classes are there in java?

630


Explain the Propertie sof class?

695


What are register variables what are the advantages?

542


What are the methods used to implement for the key object in the hash map?

658






What are the benefits of immutable objects?

630


What does flagged out mean?

665


What makes a function well defined?

640


What is the purpose of javac exe?

651


What is the lifetime and scope of a variable?

629


Explain treeset?

680


What do you mean by platform independence? What is an interface?

647


what is heap memory?

758


What is json parser in java?

706


What do you mean by access modifier?

644