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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is java a security risk?

799


Can an interface implement another interface?

782


What is the size of an array?

776


How do you implement singleton class?

752


How does regex work?

737


Where is java located?

740


What is composition in java?

954


What is the difference between interface & abstract class?

802


When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?

1019


Can we overload the constructors?

756


Can you instantiate the math class in Java?

811


What is lambda in java?

758


What is the file type?

811


Explain about the performance aspects of core java?

777


What is java developer skills?

745