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


Please Help Members By Posting Answers For Below Questions

What is the difference between delete and delete[]

923


What is a ternary operator in java? What is an interface?

762


What is this () in java?

761


How to sort a collection of custom Objects in Java?

826


What data type is true or false?

782


How many types of string data types are there?

758


Can we modify the throws clause of the superclass method while overriding it in the subclass?

775


What is replacefirst in java?

781


What is the hashcode () and equals () used for?

731


Which collection does not allow duplicates in java?

708


How many bytes is a string?

831


Difference between Preemptive scheduling vs. Time slicing?

790


Can we execute java program without main method?

733


What is the difference between class & structure?

788


What are the access modifiers in java?

798