• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final class

 
kiran kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A final class can be overloaded? Is String and StringBuffer are final classes?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you cannot override final class(final class cannt subclasses)


String:you cannt override its method ..since String is a final class but StingBuffer is not a final class
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A final class can be overloaded


You can't overload classes. You can overload methods. Overloading is where you provide more than one method with the same name an return type, but different parameters. e.g. :
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one final class can't be extends.

Is String and StringBuffer are final classes?


yes.
 
Barney Middleton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know you cant over-ride it?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barney,

Welcome to JavaRanch!

What does "it" mean in your question: final classes in general, or String, or String's methods? The rule is that you can't create a subclass of a final class at all; therefore if you can't create a subclass, there's no way to override the methods of a final class, right?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rahul dravid:
A final class can be overloaded? Is String and StringBuffer are final classes?

Classes can not be overloaded, and the final keyword does not have anything to do with overloading.

Final classes cannot be subclassed.

In the API documentation you can see that classes java.lang.String and java.lang.StringBuffer are both final.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic