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 does thread synchronization occurs inside a monitor?
What’s the difference between the methods sleep() and wait()?
What is type inference in java8?
Is null in java?
What are static initalizers in java ?
What ide should I use for java?
What is charat java?
What are advantages and disadvantages of OOPs?
List any five features of java?
Can we extend a class with private constructor?
Define max and min heap, also the search time of heap.
how we can create packages in java?
What is the generic class?
Is it possible to use string in the switch case?
What is getclass () getname () in java?