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 the difference between array list and vector in java?
Can we declare an interface as final?
What is java object name?
Can we call virtual funciton in a constructor ?
Explain a few methods of overloading best practices in java?
Can a class extends itself in java?
What is the difference between delete and delete[]
What is the default access specifier for variables and methods of a class?
Which methods are used during serialization and deserialization process?
Why isn’t there operator overloading?
What are the principle concepts of oops?
What is the declaration statement?
How are the elements of a gridbaglayout organized in java programming?
What is variable explain?
What is http client in java?