Â
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]