Can we override static methods?

Answer Posted / neha jain

dear yogesh
sory for wrong answer we can not override static method
with static method that known as method hiding.plz view
following example
Briefly, when you override a method, you still get the
benefits of run-time polymorphism, and when you hide, you
don't. So what does that mean? Take a look at this code:

class Foo {
public static void classMethod() {
System.out.println("classMethod() in Foo");
}

public void instanceMethod() {
System.out.println("instanceMethod() in Foo");
}
}

class Bar extends Foo {
public static void classMethod() {
System.out.println("classMethod() in Bar");
}

public void instanceMethod() {
System.out.println("instanceMethod() in Bar");
}
}

class Test {
public static void main(String[] args) {
Foo f = new Bar();
f.instanceMethod();
f.classMethod();
}
}
If you run this, the output is
instanceMethod() in Bar
classMethod() in Foo

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is core java important?

576


What is the use of toarray () in java?

545


What is the difference between array and array list in java?

608


Is zero a positive integer?

537


How can we break singleton in java?

528






What is a flag and how does it work?

515


What is generic class?

652


Why arraylist is used in java?

556


What are the steps involved to write rmi based programs?

573


Why webdriver is an interface?

587


What do you mean by ordered and sorted in collections in java?

558


Which programming language is best in future?

529


What do you mean by inner class in java?

573


placement papaers of spring computing technology

1029


explain multi-threading in java?

564