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
Is string is a keyword in java?
Howto get an object that will perform date & time calculations then format it for output in some different locales with different date style.can ne1 tel me the answer of this question.pls
Can we instantiate interface in java?
How are variables stored?
What class of exceptions are generated by the java run-time system?
Explain the selection sort algorithm and state its time complexity?
What is mean by exception?
What is the impact of declaring a method as final?
What is the difference between JDK and JVM?
Explain scope or life time of local variables in java?
In how many ways we can do synchronization in java?
How does hashset work in java?
How do you download stubs from Remote place?
How many characters is 16 bytes?
what is difference betweem home interface and remote interface?