Search the web
Sign In
New User? Sign Up
Java_Official · Java SE . EE . ME . AJAX . Web services
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Inheritance Question. Pls Respond.   Message List  
Reply | Forward Message #31753 of 32218 |
Re: [Java] Inheritance Question. Pls Respond.

 
Basically scale method is not overrided Because it has different parameters in
both classes.............
 
The rule is that in polymorphism if a method is overrided then the child class
method is invoked........ and if a method exist in parent class and not
overrided in child class then the parent class method is invoked...........
2ndly in polymorphism if a method exist in child and not exist in parent then
there is an compile time error............. ok
 
Regards,
 
M. Hassan


--- On Tue, 11/11/08, hasan <hasanbacak@...> wrote:

From: hasan <hasanbacak@...>
Subject: Re: [Java] Inheritance Question. Pls Respond.
To: Java_Official@yahoogroups.com
Date: Tuesday, November 11, 2008, 12:56 PM






hi,

i think that is because you use different parameters in scale methods.

at s.scale(1), 1 is thought as integer not long. change long to int. it will
resolve

____________ _________ _________ __
From: Chooti Baba <nibm963@yahoo. com>
To: Java Official <java_official@ yahoogroups. com>
Sent: Monday, November 10, 2008 7:42:53 AM
Subject: [Java] Inheritance Question. Pls Respond.

Hi Gurus,

Could you pls explain me why the following code is printing "Scale Shape"
instead of "Scale Circle"

class Circle extends Shape
{

public void scale(int x)
{
System.out.println( "Scale Circle");
}

public static void main(String args[])
{
Shape s = new Circle();
s.scale(1);
}

}

class Shape
{
public void scale(long x)
{
System.out.println( "Scale Shape");
}
}

Regards

Chooti Baba

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]


















[Non-text portions of this message have been removed]




Thu Nov 13, 2008 9:44 am

sawan_9
Offline Offline
Send Email Send Email

Forward
Message #31753 of 32218 |
Expand Messages Author Sort by Date

Hi Gurus, Could you pls explain me why the following code is printing "Scale Shape"   instead of "Scale Circle" class Circle extends Shape {     public...
Chooti Baba
nibm963
Offline Send Email
Nov 10, 2008
7:28 pm

Because the signatures do not match on your scale() methods you have not overridden the scale() method of the Shape class, but you have created a new scale()...
Eric Jones
dblacksta
Online Now Send Email
Nov 12, 2008
12:24 am

It's because, in main(), s is a reference to a Shape object. Thus, s.scale (1) calls the Shape implementation of scale. I'm not sure, but I believe this is...
Java Guy
mmjavaguy
Offline Send Email
Nov 12, 2008
12:24 am

The output is correct since the method scale(int) in Circle doesn't really override the Shape's version (scale(long)) which accept 'long' as parameter instead...
Tanvir Faraj
tanvir_faraj
Offline Send Email
Nov 12, 2008
12:24 am

Dear Chooti Baba, Because your calling scale method on reference of the Shape class. If you call scale method using object of Circle (new Circle().scale(1))...
sreekanth gundagoni
sreekanth_aug16
Offline Send Email
Nov 12, 2008
12:24 am

hi, i think that is because you use different parameters in scale methods. at s.scale(1), 1 is thought as integer not long. change long to int. it will resolve...
hasan
hasanbacak
Offline Send Email
Nov 12, 2008
12:24 am

@hasan, this is not due to different parameters. If you call s.scale(1) where scale is accepting a long parameter then it (1) would dynamically converted to...
Tanvir Faraj
tanvir_faraj
Offline Send Email
Nov 13, 2008
9:05 pm

  Basically scale method is not overrided Because it has different parameters in both classes.............   The rule is that in polymorphism if a method is...
Æ’ M. HÃ¥$$...
sawan_9
Offline Send Email
Nov 13, 2008
9:05 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help