Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Can you have a constructor in abstract class?

Answers were Sorted based on User's Feedback



Can you have a constructor in abstract class?..

Answer / saurabh

public class xyz : abc
{
int r = 10;

public xyz()
{
r = 35;


}


}
public abstract class abc
{
public int i = 0;
public abc()
{
i = 10;
}
}

sure , we can create constructor in abstract class.

Is This Answer Correct ?    0 Yes 0 No

Can you have a constructor in abstract class?..

Answer / sadiq

Yes. Abstract class can have constructor.
But abstract class cannot be instantiated,how we can call
constructor? Using super()(calls super class constructor) in
the subclass which extends abstract class.

Is This Answer Correct ?    0 Yes 0 No

Can you have a constructor in abstract class?..

Answer / suresh

any class which extends with an object class should have a
constructor whether a class is abstract class or not.
if a abstract class is super class to some sub classes,
then the abstract class should extneds with oject class.
EX: abstract class A{
A{
super(); /// it ll give a call to super class
/// super() we can use only in
constructor
}

}
class B extends A{

}
means any class should extnd with super class.
because of this abstract classes are not 100% abstract.
interface is 100% abstract.

Is This Answer Correct ?    0 Yes 1 No

Can you have a constructor in abstract class?..

Answer / 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

Can you have a constructor in abstract class?..

Answer / vivek

Yes you can have only non parameterized constructor in
abstract class, Because for parameterized constructor we
will have to make instance of abstract class which is not
possible.

Is This Answer Correct ?    0 Yes 1 No

Can you have a constructor in abstract class?..

Answer / neelamadhab mallick

A Abstract class never can be instanciate. if a concrete
method present inside the abstract class with the return
type of the same class, then it is possible to create the
object, but constructor will not called.

Is This Answer Correct ?    11 Yes 22 No

Can you have a constructor in abstract class?..

Answer / ashokmail.java@gmail.com

No. you can't make instance of abstract class.

Is This Answer Correct ?    42 Yes 62 No

Can you have a constructor in abstract class?..

Answer / naveen

a abstract class can contain abstract methods and concrete methods, to initiate and use these method we can create the object and also a constructor

Is This Answer Correct ?    7 Yes 27 No

Post New Answer

More Core Java Interview Questions

why is multiple inheritance not allowed in java?

7 Answers   Elementus Technologies, Huawei, Infosys,


Explain the term virtual machine?

0 Answers   Adobe,


I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?

8 Answers   KPIT,


What is classname class in java?

0 Answers  


What is the mapping mechanism used by java to identify IDL language?

0 Answers  


How to send a request to garbage collector?

4 Answers  


What are Transient and Volatile Modifiers?

3 Answers   SAP Labs, TUP Manila,


Explain the JDB in depth & command line.

0 Answers  


Is list thread safe in java?

0 Answers  


Which arithmetic operations can result in the throwing of an arithmeticexception?

0 Answers  


List some oops concepts in java?

0 Answers  


What is static binding and where it occurs?

4 Answers  


Categories