wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 924
    
    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.


}
Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 175
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: does this code is method hiding
 
Similar Threads
How to store method return type in primitive
testing String as immutable
final/private method......
Illegal start of expression error
Combination of Abstract and Private Modifiers in a Method Declaration