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 |
What is difference between overloading and overriding in java?
State the difference between strings and arrays.
Does it matter in what order catch statements for filenotfoundexception and ioexception are written?
What is the purpose of abstract class?
What is wrapper class html?
What is rmi and steps involved in developing an rmi object?
can you use the two main method in same class?how?
4 Answers DELL, Geosoft, SparkTG,
What is user defined exception?
What is meant by 'Class access modifiers'?
What is the transient keyword?
did interface can implementation method ? i know its not possible but my interviewer said its possible ..but how..? any one have idea ???
Can java object be locked down for exclusive use by a given thread?