Can an abstract class have a constructor?
Answer / jag bhushan
yes,
we can have constructor in abstract class.
But we can not make instance of the abstract class.
instead we can make a reference to that abstract class.
and when we make a new object of the class which extends
the abstract class, the constructor of abstract class get
called.
see the code for example:
public abstract class TestAbstract {
TestAbstract(){
System.out.println("...in abstract class'
constructor");
}
public abstract void showAbstract();
public void show(){
System.out.println("...in show");
}
}
public class Test extends TestAbstract{
public static void main(String[] args) {
TestAbstract ta = new Test(); // onstructor
call
ta.showAbstract();
ta.show();
}
public void showAbstract() {
System.out.println("...in showAbstract");
}
}
Is This Answer Correct ? | 70 Yes | 2 No |
Which package has light weight components?
How many Java environments are there?
1 Answers Phantom Technologies,
What is a conditional statement explain with example?
Write java program to reverse string without using api?
What is a lightweight component?
What is unicode?
Explain when classnotfoundexception will be raised ?
How we can generate random numbers in java?
What is the multi-catch block in java?
What is the difference between jsp and servlet?
What is the difference between method and constructor ?
What are the differences between heap and stack memory in java?