• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance problem

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
making a class final and
making its constructors private both do the same.
am I correct?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Making a class final means that the class cannot be subclassed, but you can create instances of the class. If you mark the constructor of a class private, neither can it be subclassed, nor can you create instances of the class outside the class itself...
 
Ranch Hand
Posts: 45
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No it doesnt.

Differences exist.
If a class is final it can be still instantiated in other classes' methods.
But if a class' constructors are made private, it can be instantiated only in that classes' methods.Not in other classes methods.


Please somebody correct me if I am wrong
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thanks for the replies guys
 
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


making a class final and
making its constructors private both do the same.
am I correct?


Certainly not
1.Making a class final means we can't inherit it but we can create instance of final class.

2.Making a contructor final means we cannot make instance of constructor class in other class.
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sumit kothalikar wrote:


making a class final and
making its constructors private both do the same.
am I correct?


Certainly not
1.Making a class final means we can't inherit it but we can create instance of final class.

2.Making a contructor final means we cannot make instance of constructor class in other class.



Constructor can't be final.
reply
    Bookmark Topic Watch Topic
  • New Topic