This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "does this code is method hiding" Watch "does this code is method hiding" New topic
Author

does this code is method hiding

Abdul Aatif
Greenhorn

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.


OCA7
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 923
    
    1

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.


}


OCPJP 6(100 %) OCEWCD 6(91 %) OCPJBCD(93%)
Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 163
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: does this code is method hiding
 
Similar Threads
final/private method......
Combination of Abstract and Private Modifiers in a Method Declaration
Illegal start of expression error
How to store method return type in primitive
testing String as immutable