This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Static methods can be inherited and overrriden, something wrong!!! 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 » Java » Java in General
Bookmark "Static methods can be inherited and overrriden, something wrong!!!" Watch "Static methods can be inherited and overrriden, something wrong!!!" New topic
Author

Static methods can be inherited and overrriden, something wrong!!!

Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
public static void main (String... arg) throws Exception {
B.sleep();
// the output is "I want to sleep, it is late"
//and if you activate sleep method in B the output will be "B"
}
}

class A {
public static void sleep() {
System.out.println("I want to sleep, it is late");
}
}

class B extends A{
/*
public static void sleep() {
System.out.println("B");
}
*/
}

// there is no object there So What is happened


SCJP 5
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See Overriding vs. Hiding.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
Consider Paul's rocket mass heater.
 
subject: Static methods can be inherited and overrriden, something wrong!!!
 
Similar Threads
Thread.sleep() does not release lock?
override sleep method
New to threads, need some help
Polymorphism and casting
Late & Early binding