Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

can a static method be overridden

Answer Posted / raghvendra

Look at the code and resule below and Interpret it
yourself .. :) .. it is pretty easy.

public class A {
public static void staticMethod(){
System.out.println("Static: I print from
A");
}

public void nonStaticMethod(){
System.out.println("Non Static: I print
from A");
}

}

public class B extends A{
public static void staticMethod(){
System.out.println("Static: I print from
B");
}

public void nonStaticMethod(){
System.out.println("Non Static: I print
from B");
}
}

public class Launcher {

public static void main(String[] args) {
A a = new A();
B b = new B();
A obj = new B();

System.out.println("obj instanceof A : " +
(obj instanceof A));
System.out.println("obj instanceof B : " +
(obj instanceof B));

a.staticMethod();
a.nonStaticMethod();

b.staticMethod();
b.nonStaticMethod();

obj.staticMethod();
obj.nonStaticMethod();

}
}

Consol Output:

obj instanceof A : true
obj instanceof B : true
Static: I print from A
Non Static: I print from A
Static: I print from B
Non Static: I print from B
Static: I print from A <--- See the difference here.
Non Static: I print from B <--- See the difference here.


Good luck!

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by Socket Programming?

1033


What is the relationship between an event-listener interface and an event-adapter class?

1078


Explain the difference between object state and behavior?

995


How are commas used in the intialization and iteration parts of a for statement?

1050


how do you Handle Front End Application data against DB with example?

1917


If I wanted to use a solarisui for just a jtabbedpane, and the metal ui for everything else, how would I do that?

996


For which statements does it make sense to use a label?

1015


Where can I ask questions and make suggestions about seam?

1016


which book is better for jdbc ,servlets and jsp

2049


How task's priority is used in scheduling?

2240


What is the difference between the session.update() method and the session.lock() method?

965


What are the different class loaders used by jvm?

1048


What are the different approaches to represent an inheritance hierarchy?

1018


Why does the option tag render selected=selected instead of just selected?

1125


What is the immediate superclass of the applet class?

1028