In Inheritence concept, i have a static method in super
class and i am inheriting that class to one sub class.in
that case the static method is inherited to sub class or
not????
Answer Posted / mohan
static methods can be inherited into sub class also..we can
override the static methods also..
Here is the example code
package files;
class A
{
public static void test()
{
System.out.println("static override A");
}
}
class B extends A
{
public static void test()
{
A.test();
System.out.println("static override B");
}
}
public class StaticInheritance {
public static void main(String args[])
{
B b = new B();
b.test();
}
}
Output:
static override A
static override B
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the difference between delete and delete[]
What is a ternary operator in java? What is an interface?
What is this () in java?
How to sort a collection of custom Objects in Java?
What data type is true or false?
How many types of string data types are there?
Can we modify the throws clause of the superclass method while overriding it in the subclass?
What is replacefirst in java?
What is the hashcode () and equals () used for?
Which collection does not allow duplicates in java?
How many bytes is a string?
Difference between Preemptive scheduling vs. Time slicing?
Can we execute java program without main method?
What is the difference between class & structure?
What are the access modifiers in java?