Hi Friends, can u give me Real Time example for interface
and abstract class.(With Banking Example)

Answer Posted / amit singh

hi pushpa don't go with the book think that
i'm going to tell you what is the imagine
abstract class Human
{
public abstact void eat();
}


thereis osme class is Amit ,Apoorva,and Imarana
they both in hierarchy ofthe Human class theu all extend
this class
class Amit extends Human
{
public void eat()
{
Systm.out.println("eat biryani")
}
}
classApoorva extends Human
{
pulic void eat())
{
Sysetm.out.println("eat food");
}
}
class Imrana extends Human
{
public void eat()
{
System.out.println("eat teh Dosa");
}
}
}
someans to say that theare is same hierarchy means Human
so you want toextends it just for inner world Human
2)
second pointis srise that what you think about the outer
world imagine in outre world there is another class Lizard
it aldso want ot use the functionality eat
that this particular class can extends this i don't think
so and you too
so this is the outer world class this is not in the
hierrachy of the Human so think
i am goin to make the interface for that touse this for
alll world class object whther they are in the hierrrachy
of any superr class are not

interface Nature
{
void eat();
}

class Lizard implements Mature
{

public void eat()
{
System.out.println("eaa mosquito");
}
}

and i'm too going to use this functionality so tell me
isthsii wherer the class in the same hoerrarchy are not

class Amit implements Nature
{

public void eat()
{
System/oput.println("eat any thing");
}
}
}
so this the possible to us this wiytout going any hoerarchy
so if the inner world you should to use abstrac class
but in to use functionality intyhe outer world or inner
world u should to use interface.
i think you got this
amitsing2008@@gmail.com
amit09mca(scjp1.5)

Is This Answer Correct ?    13 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it possible to write a regular expression to check if string is a number?

538


How do you find the independent variable?

511


What is the significance of listiterator?

567


we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.

1568


how to handle exceptions in ejb?

1867






Discuss 2D arrays.

606


How to do a true java ping from windows?

612


What is an error in java?

637


What does opcode mean?

533


What are "methods" and "fields"?

568


Can we serialize arraylist in java?

538


What is bitwise complement?

498


What is nextint java?

544


Are arrays static in java?

578


What is a nullable field?

575