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 / mohan
static methods can be inherited into sub class also..we can
override the static methods also..
Here is the example code
package files;
class A
{
public static void test()
{
System.out.println("static override A");
}
}
class B extends A
{
public static void test()
{
A.test();
System.out.println("static override B");
}
}
public class StaticInheritance {
public static void main(String args[])
{
B b = new B();
b.test();
}
}
Output:
static override A
static override B
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How do you declare an empty string?
When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?
What is a java object and java application?
String class is defined under which package in java?
What do negative exponents mean?
How do you sort in descending order in java using collections sort?
What is the use of keywords in java?
What do you mean by synchronized non access modifier?
What is difference between iterator access and index access?
Is java util list serializable?
What environment variables are required to be set on a machine in order to run Java programs?
What is heterogeneous in java?
Why are the methods of the math class static?
What is the difference between final, finally and finalize() in java?
If a class is declared without any access modifiers, where can the class be accessed?