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
What is return in java?
Explain the polymorphism principle?
What does it mean that a method or field is “static”?
Will set allow duplicates in java?
Difference between final and effectively final ? Why is effectively final even required ?
Does the order of public and static declaration matter in main method?
Is java written in c?
What is the use of jtable?
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
Write a java program to check if a number is prime or not?
What are the different types of multitasking?
what is server side caching?
Does java support multiple inheritance or not?
What is gui programming?
How much is a java license?