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...

what is abstrac class? why it is use?

Answer Posted / rstv

Abstract classes are classes that contain one or more
abstract methods. An abstract method is a method that is
declared, but contains no implementation. Abstract classes
may not be instantiated, and require subclasses to provide
implementations for the abstract methods. Let's look at an
example of an abstract class, and an abstract method.

Suppose we were modeling the behavior of animals, by
creating a class hierachy that started with a base class
called Animal. Animals are capable of doing different
things like flying, digging and walking, but there are some
common operations as well like eating and sleeping. Some
common operations are performed by all animals, but in a
different way as well. When an operation is performed in a
different way, it is a good candidate for an abstract
method (forcing subclasses to provide a custom
implementation). Let's look at a very primitive Animal base
class, which defines an abstract method for making a sound
(such as a dog barking, a cow mooing, or a pig oinking).

public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}

public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60
minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}

public abstract void makeNoise();
}
Note that the abstract keyword is used to denote both an
abstract method, and an abstract class. Now, any animal
that wants to be instantiated (like a dog or cow) must
implement the makeNoise method - otherwise it is impossible
to create an instance of that class. Let's look at a Dog
and Cow subclass that extends the Animal class.

public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark!
Bark!"); }
}

public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo!
Moo!"); }
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Whether it is possible to share a single instance of a memcache between multiple php projects?

990


How to calculate the difference between two dates using php?

1034


What is the use of pear in php?

996


Explain me is multiple inheritance supported in php?

1052


my english is not too good then what we apply for a php programer post

2588


What does $_env mean?

982


Explain me what is the difference between $_files['userfile']['name'] and $_files['userfile']['tmp_name']?

896


Is string php function?

1051


How to select a database in php?

1060


Tell me how can I display text with a php script?

960


What is difference between array_merge and array_combine?

1053


What is env in laravel?

1003


Is php faster than python?

1021


What is escaping to php?

957


What is laravel php?

1008