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 codebase?
what are three ways in which a thread can enter the waiting state? : Java thread
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
What do you understand by abstract classes?
What is field name?
Given a singly linked list, determine whether it contains a loop or not without using temporary space?
Explain when we should make an instance variable private.
Can we override constructors?
What is difference between public static and void?
What is the difference between delete and delete[]
Can finally block be used without a catch?
What is a dot notation?
How can we find the actual size of an object on the heap?
Can java arraylist hold different types?
Is a case study a method or methodology?