Can you have a constructor in abstract class?
Answer Posted / swapnil bhosale
ya ,we can define and call costructor in abstract class but just by using super keyword in base class ,but keep in mind we cannot create instance ob abstract class,this just another way to call contructor in abstract class,go run and see o/p
import java.io.*;
abstract class A
{
A()
{
System.out.println("hi am conS in absT");
}
}
class AA extends A
{
AA()
{
super();//calling abstract constructor
System.out.println("hi i am conS in sub class ");
}
}
class AbstConst2
{
public static void main(String arg[])
{
AA ob=new AA();//creating instance of base class consT
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is import java util arraylist?
What is the size of boolean variable?
Why wait and notify methods are declared in object class?
What are the steps in the jdbc connection?
What is return code?
Is there any case when finally will not be executed?
How do you write a scanner class in java?
What is matcher in java?
Which class is used by server applications to obtain a port and listen for client requests?
Explain method overloading?
What is the purpose of skeleton and stub?
What is indexof?
Can we override final method?
How to sort list of list in java?
What is nullpointerexception?