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????

Answers were Sorted based on User's Feedback



In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / venkat.kanneganti

Hi,static methods are methods are inherited.
example
class A {
static void methA() {
System.out.println("inside methA");
}
}
class B extends A {
public static void main(String[] args){
B.methA();
}
}
output:inside methA

Is This Answer Correct ?    20 Yes 3 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / eswar

As per my knowledge static method can't be subclass and
override.

Is This Answer Correct ?    8 Yes 4 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / muthu pandi

The static method is may inherite in the sub class.

Is This Answer Correct ?    4 Yes 2 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / dhawal

first understand meaning of static keyword,when we use
static keyword before any data type or before method then
single copy of that method or variale crated in memory,and
use that copy for only that particular class,means as far my
knowledge we can not use static method in subclass.

Is This Answer Correct ?    5 Yes 3 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / 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

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / chak de

Static Methods are NOT inherited.

Keep it in Mind. that's it.

Is This Answer Correct ?    3 Yes 2 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / shivaprasad

Definitely the sub class inherits the static method in
super class.

Is This Answer Correct ?    2 Yes 2 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / 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

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / dhanunjaya

see below example it is possible to inherite the static methods from the parent class

class Test{

void m1(){

System.out.println("test instance method");
}

static void m2(){

System.out.println("test static method");
}

}

class Demo extends Test{


void m3(){

System.out.println("demo instance method");
}


public static void main(String ar[]){
System.out.println("main method");
Demo d=new Demo();

d.m3();
d.m2();
}
}
o/p:main method
demo instance method
test static method

Is This Answer Correct ?    0 Yes 0 No

In Inheritence concept, i have a static method in super class and i am inheriting that class to on..

Answer / ramana

As per my knowledge static method can not be inhertated ,
but we use the same concept provideing that method hidding
concept.i.e we should not override the super class static
method in subclass.we just declare in subclass under
hidding concept.

Is This Answer Correct ?    5 Yes 7 No

Post New Answer

More Core Java Interview Questions

Can a constructor call the constructor of parent class?

0 Answers  


What are multiple inheritances? Is it supported by java?

0 Answers  


what is polymorhism what is inheritance? what is Abstract n Interface? what if two interfaces have same method and a concrete class is implementing both the interfaces. Will there be a compilation error? What are mutable and immutable classes? How can u make a class mutable? when will u use dem ...explain with example? what is overriding and overloading? what is garbage collection? what is Thread? how do dey communicate? what are the different ways of implementing ? have u used any messaging technologies? what is synchronization? what are some additions in java 1.5? what are generics? whst is advanced for loop? what is finally block? can u have a try in finally? yes!! can u have a finally in finally? how do you write junits? when is a object eligible for garbage collection?explain? a = null and b has ref to a will b be eligible to be garbage collected? sql questions like diff joins? how do dey work? exception handling? what is marker interface? what is the need??

0 Answers   JPMorgan Chase,


Explain the scope or life time of class variables or static variables?

0 Answers  


Given: 11. public static void main(String[] args) { 12. Integer i = uew Integer(1) + new Integer(2); 13. switch(i) { 14. case 3: System.out.println(”three”); break; 15. default: System.out.println(”other”); break; 16. } 17. } ‘What is the result? 1 three 2 other 3 An exception is thrown at runtime. 4 Compilation fails because of an error on line 12.

9 Answers  






What happens if a constructor is declared private?

0 Answers  


what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????

0 Answers   HCL, SAP Labs, Vital Soft,


When is an object subject to garbage collection?

0 Answers  


When is finally block not called?

0 Answers  


Why ArrayList class is not a synchronized class and why it is not a thread safe class? explain

1 Answers  


Which is faster call by value or call by reference?

0 Answers  


What is a priority queue java?

0 Answers  


Categories