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

How do you declare an empty string?

605


When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?

553


What is a java object and java application?

559


String class is defined under which package in java?

604


What do negative exponents mean?

532






How do you sort in descending order in java using collections sort?

478


What is the use of keywords in java?

538


What do you mean by synchronized non access modifier?

550


What is difference between iterator access and index access?

634


Is java util list serializable?

521


What environment variables are required to be set on a machine in order to run Java programs?

600


What is heterogeneous in java?

476


Why are the methods of the math class static?

566


What is the difference between final, finally and finalize() in java?

502


If a class is declared without any access modifiers, where can the class be accessed?

581