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 |
how to make a un-checked exception as a checked exception one.
How to perform merge sort in java?
Can we override the static methods?
If a class is declared without any access modifiers, where may the class be accessed in java programming?
how to deploy tomcatserver to weblogic server? write d following steps?
Is java based on c?
Why call by value prevents parameter value change?
How does list work in java?
2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?
Can a class have more than one object?
Can we create constructor in abstract class ?
How do you achieve singleton?