2 posts in topic
Flat View  Flat View

Posted By:   geeta_kalyani
Posted On:   Thursday, December 6, 2001 07:29 AM

what is the difference between final classes and abstract class?

Please use html tags to format code blocks.

Re: inheritance

Posted By:   Nitesh_Naveen  
Posted On:   Friday, December 7, 2001 01:21 PM

A final class is a fully defined class (ie all the methods are defined) which cannot be inherited by another class. When you can declare that your class as final, your class cannot be subclassed. Some extract from the Java Doc...
 There are (at least) two reasons why you might want to do this: 
1. To increase system security by preventing system subversion
  One mechanism that hackers use to subvert systems is to create a subclass of a class
  and then substitute their class for the original.
  The subclass looks and feels like the original class but does vastly different things,
  possibly causing damage or getting into private information.
2. For reasons of good object-oriented design
  You may think that your class is "perfect" or that, conceptually, your class should have no subclasses

An abstract class is a skeletal class defined which is meant to be subclassed only. You cannot instantiate an abstract class. Sometimes, a class that you define represents an abstract concept and, as such, should not be instantiated.

Click here to read more on abstract classes
Click here to read more on final classes

Re: inheritance

Posted By:   Benoit_Quintin  
Posted On:   Thursday, December 6, 2001 12:48 PM

here's a little starter : http://java.sun.com/docs/books/tutorial/java/javaOO/classdecl.html

It's exaclty what it says there, a final class cannot be extended(as in

final class A {..}
class B extends A {} //illegal
While an abstract class cannot be instantiated (as in

abstract class A {}
new A() //illegal
About | Sitemap | Contact