• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what's the difference between "override" and "hide"?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following two classes:

a. Which method overrides a method in the superclass?
b. Which method hides a method in the superclass?
c. What do the other methods do?
(Code formatted for readability)
[ November 12, 2002: Message edited by: Michael Ernest ]
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Mike
You cannot override static and private methods - you can hide them!
You can read about overriding&hiding in JLS 8.4.8.2 and
j-Think(Overriding,Overloading,...)
Regards,
Jamal Hasanov
www.j-think.com
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot !
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The j-think article says that private methods cannot be overridden.
The code below compiled successfully.
What am I missing here?

Thanks.
Deepa
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not overriding the private method. You are hiding it (and you wouldn't be able to call it anyway).
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, compiling this code gives you 2 compile time errors, the declarations of methodOne(), methodThree() in class B are illegal


C:\Documents and Settings\Administrator\My Documents\Nov.java:12: methodOne(int) in Nov cannot override methodOne(int) in ClassA; methodOne(int) and methodOne(int) are static
public static void methodOne(int i) {
^
C:\Documents and Settings\Administrator\My Documents\Nov.java:16: methodThree(int) in Nov cannot override methodThree(int) in ClassA; overridden method is static
public void methodThree(int i) {
^
2 errors


Also these 2 classes can't be declared in the same file, since they're both declared public.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alfred Kemety:

Also these 2 classes can't be declared in the same file, since they're both declared public.


I would have said the same thing, by Simon Roberts hit me with a stunner the other day; I'm still not sure I even heard him right, but he insists that nothing in the spec prevents an implementation of the compiler from allowing two public classes in the same file.
This is something I have been repeating the opposite of for years, so I have no idea what Simon meant unless I misunderstood him, but when things cool down for him I'll inquire. Meantime, I'm in search of a compiler that does in fact allow two public classes in one text file.
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmmm, well, you can say there is no spec that says 2 classes can't be declared public in the same file, since you can declare a public nested/inner class and a public top level class in the same file of course, but the spec say that a top level public class should be declared in a file with the same name with an extension java so as to be a legal source file.
[ November 12, 2002: Message edited by: Alfred Kemety ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic