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

2372


What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

1062


How can I scroll through list of pages like the search results in google?

969


Can I map more than one table in a cmp?

1087


wahts is mean by dynavalidatorform in struts/

2080


Define aop(assepct oriented programing)?

1183


What do you know about seam?

1061


Which class is the immediate superclass of the menucomponent class?

1205


When a thread blocks on i/o, what state does it enter?

1097


What are various types of class loaders used by jvm?

1006


Can we sent objects using Sockets?

1147


Can I use javascript to submit a form?

1151


What classes of exceptions may be caught by a catch clause?

1041


Define prototype?

1071


the same information whether it will connect to the database or it will be used previous information?

1043