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

Hi All,

static method can never be overridden, to clear your doubt
I have written the following two java files

Base.java -->
public class Base {
public static void method(){
System.out.println("base");
}
}

Child.java -->
public class Child extends Base {
public static void method(){
System.out.println("Child");
}
public static void main(String[] args) {
Base baseObj = new Child();
baseObj.method();
baseObj = new Base();
baseObj.method();
}
}

The class file for Child.java is:
public class Child extends Base
{

public Child()
{
}

public static void method()
{
System.out.println("Child");
}

public static void main(String args[])
{
Base baseObj = new Child();
Base.method();
baseObj = new Base();
Base.method();
}
}

As you can see in case of static method object got replaced
by Class Name(here Base).
And i believe you all are aware of fact that overridden is
the case when resolution is done at Runtime.

But since in our case calling is decided at compile time,
so there is no case of overridden.

Do let me know, if you have further query

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is an isolation level?

2709


What happens when a thread cannot acquire a lock on an object?

971


What is the difference between the font and fontmetrics classes?

1082


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

1013


What is metaspace?

971


What is the difference between RMI registry and OS Agent?

1071


What is the infobus?

1036


What is the purpose of the wait() method?

1105


Difference between loadclass and class.forname?

991


Can I import same package/class twice? Will the jvm load the package twice at runtime?

1083


what is a portable component?

1929


What modifiers may be used with an interface declaration?

1073


How many times may an objects finalize() method be invoked by the garbage collector?

1043


What is synchronization and why is it important?

1036


Explain the difference between object state and behavior?

995