• 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

Hiding Methods

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
" If a class declares a static method, then the declaration of that method is said to
hide any and all methods with the same signature in the superclasses and superinterfaces
of the class that would otherwise be accessible to code in the class. A
compile-time error occurs if a static method hides an instance method. "
This is taken from JLS 8.4.6.2 .
What does the author mean by hiding of all the methods with same signature in the superinterfaces?
How can u write a static method that can hide an interface method? Does he mean to say you can implement an interface method by a static method in a class (not possible right.....)?

Could someone please clarify this?
thank you,

Saravanakumar R
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me try to explain:
class A {
public static void m1() {}
}
class B {
public void m2() {}
}
class C extends A {
//this method hides A.m1()
public static void m1() {}
}
interface E {
public void m3();
}
class F implements E {
public static void m3() {}//compiler error
}
class D extends B {
public static void m2() {}//compiler error
}
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic