• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hi Mrs sona nagee .

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First I thanks for your patient,you are so kind ,and I will call you Mrs not Mr.I think you didn't note the static method brake() is override .You said the static method cn't be override.but.....
class vehicle{
public String color = "vehicle-color";
public void drive(){
System.out.println("vehicle:drive");
}
public static void brake() {
System.out.println("vehicle:brake");
}
}
class car extends vehicle{
public String color = "car-color";
public void drive(){
System.out.println(" car:drive");
}
public static void brake() {
System.out.println("car:brake");
}
}
public class Test12{
public static void main(String args[]){
vehicle v;
car c;
v=new vehicle();
c=new car();
System.out.println("---- first object ------");
v.drive();
v.brake();
System.out.println(v.color);
System.out.println("---- second object ------");
c.drive();
c.brake();
System.out.println(c.color);
v=c;
System.out.println("---- variable of first object now points to second object, but is of type first object ------");
v.drive();
v.brake();
System.out.println(v.color);
}
}
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
yes static methods are not overridden meaning they are hidden
now what happens when a method is overridden
the method that gets called depends upon the object type
but when a method is hidden (static)
then the method that gets called is of the reference type or in other words of the class type ... since static is associated with the class.. this is entirely different from overridding
i am online if u have any more questions post it
visit this link there is an example code. this should clear your doubt
http://www.javaranch.com/ubb/Forum24/HTML/003280.html
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gzw0733 please re-register with a valid first name and last name according to our naming regualtions. http://www.javaranch.com/name.jsp
 
reply
    Bookmark Topic Watch Topic
  • New Topic