wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Guess The result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Guess The result" Watch "Guess The result" New topic

Guess The result

dilan alex

Joined: Sep 17, 2011
Posts: 27
Hi All,

Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

So what should we guess? Outputs?
John Jai

Joined: May 31, 2011
Posts: 1776
dilan alex

Joined: Sep 17, 2011
Posts: 27
Hi All,

Actually I just wanted to ask about this code snippet.

Here Prius Class extends Toyota class and as we know static methods are not overridden. But in main method I have created Prius object and calling breaking method -
Its called Toyota class breaking method. how does this happen ??
Static methods are not overridden ? is it?

this is the output i get

Vehecle Created....
Toyota Created....
Prius Created....
Toyota Breaking....

Any help??


Peter Heide
Ranch Hand

Joined: Nov 04, 2006
Posts: 31
Add this to the main method:

The output ist:

Vehecle Breaking....

The reference is of type Vehicle and the object is of type Prius. It takes the Vehicle.breaking() and not the Toyota.breaking() because both methods are static methods and they are not overridden.

It is sorta covered in the JavaRanch Style Guide.
subject: Guess The result
Similar Threads
static int not incrementing, constructor not called.
Static method can access in a subclass
Instance of Operator
Need help on inheritance...