GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 192 of 492    Print  
how and when to prevent inheritance?

  
Total Answers and Comments: 10 Last Update: May 29, 2008     Asked by: vidhya165 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 30, 2006 05:06:19   #1  
vemodharak Member Since: September 2005   Contribution: 12    

RE: how and when to prevent inheritance?
how to preventing inheritance:by a class declared as final then that calss cannot be inheritedwhen preventing the inheritance:suppose iy ur class no need to reused then only u can declare final .
 
Is this answer useful? Yes | No
January 30, 2006 05:22:22   #2  
sbarik Member Since: January 2006   Contribution: 27    

RE: how and when to prevent inheritance?

One can prevent inheritance by declaring a class with keyword final  .By declaring a class as final no other class can extend it..

final class Example

{

/*  

     Code   for u r application..

*/

}


 
Is this answer useful? Yes | No
January 30, 2006 05:55:16   #3  
vidhya165 Member Since: January 2006   Contribution: 13    

RE: how and when to prevent inheritance?

inheritance is prevented using the final method


 
Is this answer useful? Yes | No
January 30, 2006 05:57:09   #4  
subhash g.        

RE: how and when to prevent inheritance?
should provide the final keyword to class,because final classes are not inherited
 
Is this answer useful? Yes | No
January 30, 2006 12:49:55   #5  
tulasi_yl Member Since: January 2006   Contribution: 1    

RE: how and when to prevent inheritance?
Final is Keyword which is used to prevent a class to Extend..when to stop the inheritance is up to u..when u need u'r class not to be subclassed further more then  we can prevent inheritance
 
Is this answer useful? Yes | No
February 03, 2006 04:33:38   #6  
kiran        

RE: how and when to prevent inheritance?

inheritance is prevented when u are sure that your class is a child/leaf and cannot be parent of any other class.U are sure that class is already saturated with functionality and won't be much help by extending it. 

how- use keyword 'final'


 
Is this answer useful? Yes | No
March 09, 2006 00:43:31   #7  
Dhananjay Khodve        

RE: how and when to prevent inheritance?

Please don't put wrong comments here bcoz lots of people read these comments.

You can prevent inheritance by making a final class.

bye


 
Is this answer useful? Yes | No
May 17, 2006 14:50:09   #8  
Nagaraju        

RE: how and when to prevent inheritance?

if u provide

private access specifier for Constructor, in these case also it will no allow to create a subclass.

and all of us know u can use final keyword before class.


 
Is this answer useful? Yes | No
July 05, 2006 10:27:42   #9  
iyck        

RE: how and when to prevent inheritance?

If we make Final class we cannot extend, also if we make all the constructor private then we cannot extend that class, is this also prevents inheritence?


 
Is this answer useful? Yes | No
May 29, 2008 11:06:17   #10  
vinaymudgil007 Member Since: May 2008   Contribution: 36    

RE: how and when to prevent inheritance?
Two ways: -
(1) mark the class as final
(2) make its constructor private -- in this case we will also not be able to instantiate a class from any other class

any doubts, let me know


Vinny

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape