File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes can somebody explain me the difference between Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can somebody explain me the difference between" Watch "can somebody explain me the difference between" New topic

can somebody explain me the difference between

ROy Methew

Joined: Feb 19, 2005
Posts: 2
I am dont understand javas abstraction feature
As it says ,hiding unneccessary details & providing meaningful/required data only.
How a class can provide abstraction?
I mean when we create object we are taking every instance member into that
so does abstraction means static members???
give some example with small sample code thanks.

Thanks in advance.
Garry Meax
Ranch Hand

Joined: Feb 11, 2005
Posts: 31
hi Methew,

i am aslo new to java here is what i have in my notes.

// an abstract class is a class that has one or more abstract methods
// an abstract method is a method declared using the abstract keyword, but not
// an abstract class cannot be instantiated i.e. cannot be used to create
// if a class is derived from an abstract class, it must ovveride all it's
abstract methods
abstract class A{
int x;
void set_x(int a) {x=a;}
abstract void show(); // abstract method, declared, but not implemented
class a68 extends A{
void show() {System.out.println(x);}
public static void main(String args[]){
a68 o=new a68();
class a682 extends A{
void show() {System.out.println("x= "+x);}

hope that sheds some light into your problem
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58

Plz always use "CODE" UBB Code when posting code samples

kind regards
[ February 19, 2005: Message edited by: Igor Stojanovic ]
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
classes provide abstraction because the code that uses classes (uses instances of classes, that it - objects) can treat the instance as a "black box". the instance can keep some or all of its instance data (variables) private, and not expose them to its users, which can think of the object as an abstract "something" and not need to worry about how it works "inside". those users can call methods on the object and not worry about just how the methods do their work; another way of simplifying function.

for example, in other threads on this forum recently there's been discussion of the BigInteger class. instances of this class represent really huge numbers, larger than will fit in any primitive type. i happen to know that the mechanics of representing such numbers and manipulating them - doing math on them - can get quite complicated; but i don't need to know that. i can just use the BigInteger as an "abstract number" that happens to be "large" and not worry about what's going on inside it. that's abstraction.
Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66

Here we have a method justPrint() . We are not sure how this should we declare it as abstract...Since we have a method as abstract, the enclosing class should also be abstract...Look what garry has written abstract class can have both abstract and non-abstract methods...
if a class extends an abstract class then it should implement all abstract methods, else be itself declared abstract...

Now look at the code ... do some google search...
if you still need help...ask specifically...where you are getting stuck...

Prashanth Lingala

Have A Nice Day !!!
ROy Methew

Joined: Feb 19, 2005
Posts: 2
Hi M Beck,

Thank you very much for such a good explanation.

I got it
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Consider an abstract class Animal. Which the classes Cat, Mouse and Elephant will all extend. In class animal is an abstract method entitled eat(). We know that all our animals must eat, but not sure what or how they eat. By making animal an abstract class with the abstract method eat we ensure that all animals must have an eat method. But we can determine how, when, where etc... they eat in the subclasses (Cat, Mouse, Elephant).
Joel McNary

Joined: Aug 20, 2001
Posts: 1815
Don't be confused by the keyword "abstract" and the concept of "abstraction." You can use abstraction without having abstract classes. (M Beck's post shows that...)

Really, all abstraction is is hiding the implementation details from the users of that class.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Don't get me started about those stupid light bulbs.
subject: can somebody explain me the difference between
Similar Threads
Doubt about the Bridge Design Pattern
Regarding Abstraction
Can any body give me the example for abstraction.
OOPS Concept Abstraction with example
Abstraction and Encapsulation