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 collections api in java programming?
Difference between ‘>>’ and ‘>>>’ operators in java?
What are the 4 versions of java?
what is difference betweem home interface and remote interface?
How do you write methodology?
How do you invoke a method?
Explain about features of local inner class?
What is the method to expand and collapse nodes in a jtree?
What is the purpose of the file class in java programming?
What is externalizable?
What is parseint?
Is math class static in java?
Why generics are used in java?
Can a lock be acquired on a class in java programming?
Which of the following is not an isolation level in the JDBC