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 should I import for arraylist in java?
Define "Access specifiers" in java.
Can I use % with real numbers?
Can a singleton class be inherited?
Is age discrete or continuous?
What is the difference between procedural and object-oriented programs?
What is the primitive type byte?
Which is the class in java?
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
What are serialization and deserialization?
What is multithreading and its advantages?
What is nested interface?
Explain about wait() method?
How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
design an lru cache in java?