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


Please Help Members By Posting Answers For Below Questions

How hashset works internally in java?

576


What is the memory leak in java?

520


What is difference between string and stringbuffer?

485


what is the difference between Object Based Language and Object Oriented Language?

591


What is type conversion in java?

567






describe synchronization in respect to multithreading? : Java thread

491


Why we use methods in java?

527


What is parsing in grammar?

547


What is return type in java?

626


How do you use compareto?

540


What is an class?

581


What does || mean in code?

534


What is the difference between abstract class and interface1? What is an interface?

549


Can we clone singleton class in java?

504


What is jit compiler in java?

573