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
Why constructor has no return type?
How do you include a string in java?
What is local declaration?
What is the difference between import java.util.date and java .util?
What is parsing in grammar?
What does system out println () do?
What is int lol?
What is ‘is-a ‘ relationship in java?
What are the Class Libraries ?
Explain the difference between arraylist and linkedlist in java?
how do I create a runnable with inheritance? : Java thread
What is string pool in java?
What is autoboxing in java?
How to retrieve data from database in java using arraylist?
Why set do not allow duplicates in java?