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 the use of singleton?
Why string is not thread safe?
How does linkedlist work in java?
What is append in java?
Explain inner classes ?
How can you traverse a linked list in java?
What are the major advantages of internal iteration over external iteration?
Explain reverse a linked list recursive java solution?
What is boolean used for?
What is a condition in java?
Does garbage collection occur in permanent generation space in jvm?
Why java is used everywhere?
What is difference between final and finally in java?
What is the difference between class & structure?
What is the difference between object oriented programming language and object based programming language?