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 not thread safe?
Explain the importance of finally over return statement?
Is it necessary for the port addresses to be unique? Explain with reason.
What is type safety in java?
Explain the private field modifier?
Can a class extends itself in java?
What is string data type?
Difference between this() and super() in java ?
When can an object reference be cast to an interface reference in java programming?
What is the difference between a synchronized method and a synchronized block?
Can java list be null?
What is finalize() function in java?
Explain the difference between call by refrence and call by value?
What is jar?
What is a java predicate?