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 an abstract class have a constructor?

Answer Posted / jag bhushan

yes,
we can have constructor in abstract class.
But we can not make instance of the abstract class.
instead we can make a reference to that abstract class.
and when we make a new object of the class which extends
the abstract class, the constructor of abstract class get
called.

see the code for example:

public abstract class TestAbstract {

TestAbstract(){

System.out.println("...in abstract class'
constructor");
}

public abstract void showAbstract();
public void show(){
System.out.println("...in show");
}
}


public class Test extends TestAbstract{
public static void main(String[] args) {

TestAbstract ta = new Test(); // onstructor
call
ta.showAbstract();
ta.show();

}

public void showAbstract() {
System.out.println("...in showAbstract");

}

}

Is This Answer Correct ?    70 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is a method a procedure?

986


What is reverse function?

1056


Explain runtime exceptions?

1109


What is import java util arraylist?

1110


What is skeleton and stub?

985


What is a variable simple definition?

973


Define a package.

1009


Explain the importance of finally block in java?

905


write a program that list all permutations of ABCDEF in which A appears before B?

2437


who can i handle multiple client in RMI

1834


What is the difference between arraylist and hashset in java?

1054


How to reverse string in java?

1134


What are the 6 boolean operators?

1020


What classes of exceptions may be thrown by a throw statement?

908


What is difference between path and classpath variables?

1032