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
How is it possible for two string objects with identical values not to be equal under the == operator?
How many types of classes are there in java?
Explain the Propertie sof class?
What are register variables what are the advantages?
What are the methods used to implement for the key object in the hash map?
What are the benefits of immutable objects?
What does flagged out mean?
What makes a function well defined?
What is the purpose of javac exe?
What is the lifetime and scope of a variable?
Explain treeset?
What do you mean by platform independence? What is an interface?
what is heap memory?
What is json parser in java?
What do you mean by access modifier?