File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes An abstract class cannot be instantiated, but can be extended by subclasses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "An abstract class cannot be instantiated, but can be extended by subclasses" Watch "An abstract class cannot be instantiated, but can be extended by subclasses" New topic
Author

An abstract class cannot be instantiated, but can be extended by subclasses

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
Hi Everybody
"An abstract class cannot be instantiated, but can be extended by subclasses"

Can anybody tell with an example the undeline meaning of the above concept
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
hi

A class that is missing definitions for one or more methods. You can't thus create an object of that class. You must first create a subclass and provide definitions for the abstract methods. Unlike interfaces, abstract classes may implement some of the methods. Though you can't instantiate an abstract class, you can invoke its static methods.

stolen from the java glossary

the definition found here
is wrong: an abstract class does not need to have an abstract method. it can also have no methods at all or only non-abstract methods.


pascal
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
An abstract class is one that is defined as abstract, which is taken to mean that it is incomplete. More often than not, an abstract class will have one or more abstract methods. A 'real' class may extend an abstract class and provide an implementation for the abstract methods.

Robby Robson
Greenhorn

Joined: Dec 21, 2004
Posts: 9
this is why I hate "hello World" it doesn't demosrate WHY you want to use java, when you can produce the same result with on line in BASIC??


this explain the follow is incomplete butI think demostrates the concept


your creating an "animal farm" program, and on this farm you have horses,cows,ducks and gease. Horses and cows are mammals, ducks and gease are fouls

so.....

public abstract class Mammal{
public void giveBirth(){.....}

}

public abstract class Foul
{
public void layEggs() {....}
}

then ...

public class Cow extends Mammal ...
public class Duck extends Foul....
etc


the point is that even though a duck is a Foul you've never shot a "Foul"

so you can not create a "new Foul" but by creating the abstract class and extending it, then you don't have reprogram the layEggs meathod for every Foul type you make


:-)
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Robby Robson:
this is why I hate "hello World" it doesn't demosrate WHY you want to use java, when you can produce the same result with on line in BASIC??
Ah, but "Hello World!" is not meant to demonstrate that. Rather, it's only meant to teach you how the JVM kicks off your program -- its entry point. Many people find it easier to learn if they add one new concept at a time to what they already know instead of dumping it all in at once.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An abstract class cannot be instantiated, but can be extended by subclasses