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
What is a treeset in java?
What is the SimpleTimeZone class?
What are the states of thread in java?
Why do we use variables?
Why java is a platform independent? Explain
What are the features of java?
Write a program to calculate factorial in java?
give an example for encapsulation?
Why you should not use singleton?
Is null a value?
What is e in java?
Can I learn java without any programming experience?
How will you reverse a singly-link list?
Can private method static?
In java, how many ways you can take input from the console?