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

does this code is method hiding

 
Abdul Aatif
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Test{
private void m1(){


}
}
class Test2 extends Test{

private void m1(){


}


}
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep,It is.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no it is not. the subclass does not know m1 exists in the super class. in superclass m1 is declared as private. test2 does not know the existence of m1.

if you have an accessible static method in superclass and you have method with same name and args in subclass, that would have been called method hiding

public class Test{
public static void m1(){


}
}
class Test2 extends Test{

public static void m1(){ //method hiding. not overriding. static methods cannot be overidden.


}
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to elaborate on the answer given by Gurpeet anything that is declared private is only accessible within the class it is declared in.

private - only accessible within its own class.

no modifier / package-private /(the default) - accessible only within its own package.

protected - accessible within its own package and also by a subclass of its class in other packages.

public - accessible to all other classes everywhere.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic