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

Is singleton thread safe in java?

728


What is a ternary operator in java?

743


What is instance synchronization?

800


What are the differences between c++ and java?

798


In the below example, how many string objects are created?

768


How many digits is int32?

718


Write a function to find out longest palindrome in a given string?

806


How do you use spaces in java?

720


What is the purpose of the enableevents() method in java programming?

793


What is a list in java?

716


What are design patterns and please explain?

814


Can I learn java in 3 months?

748


Mention a package that is used for linked list class in java.

730


What do you mean by platform independence?

778


What are desktop procedures?

785