This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes tell me about abstract Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "tell me about abstract" Watch "tell me about abstract" New topic
Author

tell me about abstract

Tony Ben
Greenhorn

Joined: Feb 14, 2006
Posts: 7
plz explain about abstract class and abstract method .
how to use ?
when to use ?
and
where to use???

plz anybody.............
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Sounds like you're asking for an entire chapter of an introductory book. Fortunately, there are several readily available. For example, Abstract classes and methods from Thinking in Java.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
well first off, you extend abstract classes in other classes, for example;


ok, abstract methods empty, non defined, you define them in the classes
that extend, and an abstract class doesnt have to have all abstact methods
either, it can have concrete methods w/ method bodies....

well hope this helps

Monk..


You down with OOP? Yeah you know me!
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
In design, you want the base class to present only an interface for its derived classes. This means, you don�t want anyone to actually instantiate an object of the base class. You only want to upcast to it (implicit upcasting, which gives you polymorphic behaviour), so that its interface can be used. This is accomplished by making that class abstract using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents it.

The interface keyword takes this concept of an abstract class a step further by preventing any method or function implementation at all. You can only declare a method or function but not provide the implementation. The class, which is implementing the interface, should provide the actual implementation. The interface is a very useful and commonly used aspect in OO design, as it provides the separation of interface and implementation and enables you to:

Capture similarities among unrelated classes without artificially forcing a class relationship.

Declare methods that one or more classes are expected to implement.
Reveal an object's programming interface without revealing its actual implementation.

Model multiple interface inheritance in Java, which provides some of the benefits of full on multiple inheritances, a feature that some object-oriented languages support that allow a class to have more than one superclass.

When to use an abstract class?: In case where you want to use implementation inheritance then it is usually provided by an abstract base class. Abstract classes are excellent candidates inside of application frameworks. Abstract classes let you define some default behaviour and force subclasses to provide any specific behaviour.

When to use an interface?: For polymorphic interface inheritance, where the client wants to only deal with a type and does not care about the actual implementation use interfaces. If you need to change your design frequently, you should prefer using interface to abstract. CO Coding to an interface reduces coupling and interface inheritance can achieve code reuse with the help of object composition. Another justification for using interfaces is that they solve the �diamond problem� of traditional multiple inheritance as shown in the figure. Java does not support multiple inheritances. Java only supports multiple interface inheritance. Interface will solve all the ambiguities caused by this �diamond problem�.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
 
GeeCON Prague 2014
 
subject: tell me about abstract