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


Please Help Members By Posting Answers For Below Questions

Is singleton class immutable?

736


What is an inner class in java?

733


What is the final class?

758


What is generic type?

809


What is an exception in java?

890


Is java same as core java?

835


What is meant by inheritance and what are its advantages?

844


What is the difference between reader/writer and inputstream/output stream?

794


What is integer parseint?

740


What is a constructor, constructor overloading in java?

771


What is the difference between an inner class and a sub-class?

733


What is a values collection view ?

885


What is string and its types?

862


List some features of the abstract class.

803


How do generics work?

725