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
How do you find the maximum number from an array without comparing and sorting?
What is method overloading in java ?
What is a constructor overloading in java?
What is pojo class in java?
Explain the difference between jvm and jre?
Explain the difference between association, aggregation and inheritance relationships.
How many types of literals are there in JAVA?
What is nullpointerexception in java?
What is immutable state?
How many bytes is double?
What is import java util arraylist?
When we should use serialization?
Tell me how many ways are there to initialise an integer with a constant.
What is api in java?
What is an immutable class?