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
What is volatile keyword in java
Can we declare a constructor as final?
How the interruptible method gets implemented?
What is the difference between scrollbar and scrollpane?
What is argument in java?
Which programming language is best in future?
Is an object null?
Is zero a positive integer?
What is the benefit of singleton pattern?
How will you invoke any external process in java?
What is the difference between multiple processes and multiple threads?
What is set string?
Can the interface be final?
What do you mean by inner class in java?
What are multiple inheritances? Is it supported by java?