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 does module-relative mean?

1230


Where can I ask questions and make suggestions about seam?

1112


Which containers use a border layout as their default layout?

1196


What is the difference between long.class and long.type?

1174


What is the diffrence between a local-tx-datasource and a xa-datasource?

1105


What is a modular application? What does module-relative mean?

1117


Why are some of the class and element names counter-intuitive?

1213


Describe responsibilities of Activator?

2353


Difference between new operator and class.forname().newinstance()?

1178


Define aop(assepct oriented programing)?

1247


Name the class that is used to bind the server object with RMI Registry?

2220


What are the oops concept?

1132


what is the use of State Factories?

2448


To identify IDL language what mapping mechanism is used?

3984


int x=5,i=1,y=0; while(i<=5) { y=x++ + ++x; i=i+2; } System.out.println(x); System.out.println(y); System.out.println(i); How to solve this? Please explain!

1884