This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes does this code is method hiding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "does this code is method hiding" Watch "does this code is method hiding" New topic

does this code is method hiding

Abdul Aatif

Joined: Feb 08, 2012
Posts: 23
public class Test{
private void m1(){

class Test2 extends Test{

private void m1(){


Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Yep,It is.

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

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

Joined: Jan 06, 2009
Posts: 179
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.

Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
Have you checked out Aspose?
subject: does this code is method hiding
It's not a secret anymore!