File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes final class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "final class" Watch "final class" New topic

final class

kiran kumar

Joined: May 24, 2008
Posts: 18
A final class can be overloaded? Is String and StringBuffer are final classes?

Thanks & Regards,<br />Bhuvan Samrat.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 14, 2004
Posts: 10336

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. :

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
one final class can't be extends.

Is String and StringBuffer are final classes?


Brazil - Sun Certified Java Programmer - SCJP 5 About Java - Update every Week.
Guide SCJP - tips that you need know
Barney Middleton

Joined: Apr 08, 2008
Posts: 2
How do you know you cant over-ride it?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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?

[Jess in Action][AskingGoodQuestions]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15091

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: final class
It's not a secret anymore!