This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Isn't final not allow overload?

 
Daisy Kent
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package client;
import server.ServerNames;
class Retrieve extends ServerNames
{
public final int MAXCONECTIONS=MAXUSERS*10;
public static String sendName(String s)
{ return s; }
}

package server;
public class ServerNames
{
protected final int MAXUSERS=20;
public final static String sendName()
{
return "Main Server";
}
}

When run the file
it's fine
public static String sendName(String s) why?
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's illegal to hide a static final method, but you're not hiding it. You're overloading, which is perfectly OK.
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final methods can be overloaded, but not overridden. I had to show this once to my Java students
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, you might find it easier to remember all the ins and outs of overload vs. override if you think of an overloaded method as just a *completely* different method that just *happens* to have the same name as another one.
So overloaded methods don't have to follow ANY of the overriding rules -- overloaded methods can throw new checked exceptions, they can have more restrictive access, and they can go crazy when it comes to return types. As long as that argument list is different, you're free to do whatever else you want because it is a totally new and different method.
Be watching for overloaded versions of methods from Object -- try to picture the ways in which you could *think* you are overriding, say, equals() or hashcode(), but in fact you are only overloading it. Keep a sharp eye out for things like that on the exam.
Cheers,
Kathy
author, "Shroedinger's Object"
(not in bookstores, however, because we opened the box and, well, it didn't go as we'd hoped)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic