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 u give one sinario when you use Abstract Class and When
you use Interface.

Answer Posted / anjani kumar jha

First i will explain u abstract Class:--------------
Suppose
u open the car-show room which having all companys car and
user want to by a car, but user not sure about the company,
means user requirement is a good car. So he will come in ur
show room and ask about the every company car so how u gonna
to do this task.

So how u start.

First of all every car having some common characteristic.
That is
a)Color of car
b)Shape of car
c)gear in car
d)Type of car
e)Price of car
..........................etc.

So what we are doing is actually we are writing a abstract
class that is called Car and then we summarized the common
properties of car.

Why this is required because if we not
summarized the common properties of car,for every car we
have to define these common properties.Hence for that we
declare once the all common aspect of the car and the let
user choose the choice according to him.

So in abstract class we are going to define only the method
not the body and let user to allow to define his own type of
car.

abstract class Car
{
//(very important)

// we are here defining only the method not body and if any
//method end with semicolon means it is abstract method and
//if any single method in the class is abstract then class
//must be abstract. but in abstract class //we can define
the concrete method(which is not abstract) //also
public void color();
public void price();
public void types();

Class Bmw extends car
{
//here we are define the user requirement of the car that //
is bmw and we are defining the method with body also
public void color()
{
System.out.println("color of car is red");
}
public void price()
{
System.out.println("price of car is......");
}
}
Public Tata extends car
{
public void color()
{
System.out.println("color of car is blue");
}
public void price()
{
System.out.println("price of car is......");
}
}

I think u gain some fact about abstract class.


Interface------------------java dont have multiple
inheritance concept........so java using multiple
inheritance by INTERFACE.

Actually interface is a set of rules....it rquired when u
want to achieve multiple inheritance .
The set of rules says
1)all method are by default public staic and abstract
2)All the variables are public static and final.

So for interface u have to implements
Example

Class Anjani implements ABC(means abc is interface)

{

}

For further assistance u may call me
Anjani Kumar Jha
09623154095
CDAC,PUNE

Is This Answer Correct ?    2 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I am a fresher and know core java, c languge, html, css etc if I am illegible for any job then send it on my email tatranakshay276@gmail.com

1640


How is a variable stored in memory?

935


Difference between final and effectively final ?

1026


What is the function of compareto in java?

1011


What is the purpose of java?

935


List implementations of list interface?

990


Why does java have two ways to create child threads? Which way is better?

987


Explain listiterator and methods in listiterator?

960


How hashmap increases its size in java?

934


How do you print array in java?

923


Why we do exception handling in java and how many types of exceptions are there?

1048


What do you understand by access specifiers in Java?

965


Can we execute a program without main?

965


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

1021


Compare Mutex and Semaphore in java.

945