Results 1 to 4 of 4
  1. #1
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default What kinds of classes needs to be final.

    Why should a class be a final class? can some one please give real life example where a class needs to be final to serve it's purpose in object oriented design.
    Thank you.

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Hello, roots.

    I think you add the final modifier when you completed a class and you know that there will be no need for it to be the super class of some other class. For example: Let's say Planet is a subclass of Body and Earth is a subclass of Planet, but you do not get different types if Earths as you get different types of planets. Thus, the Earth class must be declared final. I think the purpose of this is to improve performance.

    Hope this helps. :)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default

    Or if you want to create a class that no one can extends due to the critical functionality in the class. A String class is an example of final class in the Java API.

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    I had a long standing doubt on final classes. May be more people can talk about their views on using final classes for themselves. Thank you tim again "you do not get different types if Earths" this is the kind of view i was talking about. Thank you wsaryada for your response.
    dont worry newbie, we got you covered.

Similar Threads

  1. UJO Framework 0.72.final
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-17-2008, 08:28 PM
  2. which are the final classes in the java APi
    By vagarwal_mca in forum New To Java
    Replies: 2
    Last Post: 01-10-2008, 02:47 AM
  3. problem with final
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 01:31 AM
  4. I have a problem with final
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 12:25 AM
  5. Poi 3.0-final
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-22-2007, 07:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •