• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

What is an abstract class? (was: scjp)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
saisreereddy surabhi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tanks henry.....
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 363
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic