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

Answers were Sorted based on User's Feedback



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

Answer / pushpa

<b>Abstract Class :</b>In an object-oriented drawing
application, you can draw circles, rectangles, lines, Bezier
curves, and many other graphic objects. These objects all
have certain states (for example: position, orientation,
line color, fill color) and behaviors (for example: moveTo,
rotate, resize, draw) in common. Some of these states and
behaviors are the same for all graphic objects—for example:
position, fill color, and moveTo. Others require different
implementations—for example, resize or draw. All
GraphicObjects must know how to draw or resize themselves;
they just differ in how they do it. This is a perfect
situation for an abstract superclass. You can take advantage
of the similarities and declare all the graphic objects to
inherit from the same abstract parent object—for example,
GraphicObject, as shown in the following figure.

Classes Rectangle, Line, Bezier, and Circle inherit from
GraphicObject

Classes Rectangle, Line, Bezier, and Circle inherit from
GraphicObject

First, you declare an abstract class, GraphicObject, to
provide member variables and methods that are wholly shared
by all subclasses, such as the current position and the
moveTo method. GraphicObject also declares abstract methods
for methods, such as draw or resize, that need to be
implemented by all subclasses but must be implemented in
different ways. The GraphicObject class can look something
like this:

abstract class GraphicObject {
int x, y;
...
void moveTo(int newX, int newY) {
...
}
abstract void draw();
abstract void resize();
}

Each non-abstract subclass of GraphicObject, such as Circle
and Rectangle, must provide implementations for the draw and
resize methods:

class Circle extends GraphicObject {
void draw() {
...
}
void resize() {
...
}
}
class Rectangle extends GraphicObject {
void draw() {
...
}
void resize() {
...
}
}

When an Abstract Class Implements an Interface
In the section on Interfaces , it was noted that a class
that implements an interface must implement all of the
interface's methods. It is possible, however, to define a
class that does not implement all of the interface methods,
provided that the class is declared to be abstract. For example,

abstract class X implements Y {
// implements all but one method of Y
}

class XX extends X {
// implements the remaining method in Y
}

In this case, class X must be abstract because it does not
fully implement Y, but class XX does, in fact, implement Y.




*************************************************************

Is This Answer Correct ?    12 Yes 0 No

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

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

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

Answer / phani kumar

The understanding of the concept is correct. But what ever
the names you choosen for the classes are not giving right
meaning, for example Imrana, Apoorva, etc... These has to
reprasent objects,not the classes.

Is This Answer Correct ?    8 Yes 1 No

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

Answer / r.jainrocks@gmail.com

Above answer is excellent answer...

thank you "Pushpa" for this great answer

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More Core Java Interview Questions

Difference between string s= new string (); and string s = "abv";?

0 Answers   Cap Gemini,


Can java list contain duplicates?

0 Answers  


why is multiple inheritance not allowed in java?

7 Answers   Elementus Technologies, Huawei, Infosys,


What state is a thread in when it is executing?

0 Answers  


Which is faster string or stringbuilder?

0 Answers  






Is set sorted in java?

0 Answers  


Why does java doesnt suuport unsigned values?

0 Answers   ABC,


can two class in a code be public??if yes then how??

2 Answers  


What is the += operator called?

0 Answers  


What is rmi and steps involved in developing an rmi object?

0 Answers  


What is thread life cycle?

0 Answers  


What does it mean to flush a file?

0 Answers  


Categories