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 / chitij mehrotra

Yes static method in the super class is inherited in the sub
class. See the example:

class Superclass
{
static int id;

Superclass()
{
id = 1;
}

public void show()
{
System.out.println("This is a non static method");
}

public static void value()
{
System.out.println("Super class static method");
}
}

class Subclass extends Superclass
{

}
public class Example
{
public static void main(String[] args)
{
Subclass sub = new Subclass();
System.out.println(Superclass.id);
Superclass.value();
System.out.println(Subclass.id);
Subclass.value();
}
}

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is return in java?

528


Explain the polymorphism principle?

551


What does it mean that a method or field is “static”?

531


Will set allow duplicates in java?

479


Difference between final and effectively final ? Why is effectively final even required ?

528






Does the order of public and static declaration matter in main method?

591


Is java written in c?

517


What is the use of jtable?

621


I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?

566


Write a java program to check if a number is prime or not?

519


What are the different types of multitasking?

633


what is server side caching?

1578


Does java support multiple inheritance or not?

578


What is gui programming?

489


How much is a java license?

502