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 do you decide when to use arraylist and linkedlist?
In java, what is the difference between method overloading and method overriding?
Can we call virtual funciton in a constructor ?
What is a method in java?
Define jit compiler?
What technique is carried out to find out if a particular string is empty?
What is an example of a conditional statement?
What are the rules for variable declaration?
What is meant by distributed application? Why are we using that in our application?
How do you read and print a string in java?
What does t in java mean?
Can we have a method name same as class name in java?
What type of variable is gender?
What is the use of generics? When was it added to the Java development Kit?
explain autoboxing in java?