Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Isn't final not allow overload?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
final methods can be overloaded, but not overridden. I had to show this once to my Java students
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic