Jay CSheth

Greenhorn
+ Follow
since Mar 17, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jay CSheth

Hi,

Just to conclude this thread, we also have to remember that static methods can't be overridden. They can be redefined in a subclass, but both are different things (redefining v/s overriding).

class Base() {
static void greet() {
system.out.println("Base ");
}
}

class Derived extends Base {
static void greet() {
system.out.println("Derived ");
}

public static void main(String[] args) {
Base b1 = new Base();
Base b2 = new Derived();

b1.greet();
b2.greet();
}
}

The output for the above would be:
Base Base

This is because, when the compiler sees b1.greet() or b2.greet(), it simply replaces it by Base.greet() ... as greet() is a static method.