wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is an abstract class? (was: scjp) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is an abstract class? (was: scjp)" Watch "What is an abstract class? (was: scjp)" New topic
Author

What is an abstract class? (was: scjp)

saisreereddy surabhi
Greenhorn

Joined: Feb 18, 2007
Posts: 7
hi.
can anyone explan me about abstract class.......and i have no idea about abstract classes before
[ February 19, 2007: Message edited by: Henry Wong ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18507
    
  40

Originally posted by saisreereddy surabhi:
hi.
can anyone explan me about abstract class.......and i have no idea about abstract classes before


An abstract class is a class that can't be instantiated. In general, you would want to make a class abstract, when some of the methods of the class are not implemented (abstract methods). This will allow your class to compile, but not directly used.

To use your abstract class, you would have to subclass from the abstract class, and implement the abstract methods.


For design reasons, there may also be other reasons why you don't want a class to be instantiated -- maybe certain methods has been implemented but incomplete.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
saisreereddy surabhi
Greenhorn

Joined: Feb 18, 2007
Posts: 7
tanks henry.....
Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
also if you don't know about abstract classes you may want to research interfaces
and the relationship between abstract classes, interfaces, and the concrete classes that implement them

I heard there are questions on the test about abstract methods passed down the line thru interfaces and into concrete classes,etc
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 346

Let us go by an example..
Imagine, you are asked to create horse, dog etc. Obviously, you would design classes like Horse, Dog etc. right? But, how many such individual classes would you design to match the entire animal kingdom? Wouldn't it be silly to repeat all the common(like eat, sleep, run etc) animal specific code for each class that you design? Smart you are.. you would simply pick out the common behavior and make it one class called "animal"! Yup, that's right.. you just want to put everything an animal is supposed to have in "animal" class. Now, imagine, someone is trying to create an instance of animal! Uh oh!! What would be that animal look like? Dog? Horse? Else what? There you are.. an animal class is not supposed to allow its instances. You should make be precise about your animal thing before you actually make an instance. Well, the animal class is now called as abstract class. It is just a concept or idea not associated with any specific instance. Other examples for abstract classes include humanbeing, employee, shape, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is an abstract class? (was: scjp)
 
Similar Threads
Why generic servlet is an abstract class?
abstract class
Abstract method
Method Overriding
inheritance