File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance" Watch "Inheritance" New topic
Author

Inheritance

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi please go through and find a solution for this atleast in a different way.

You are given a class hierarchy with an instance of the class Dog. The class Dog is a child of mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string "move". The class mammal overrides this method and prints out the string "walks". The class Dog overrides this method and prints out the string "walks on paws". Given an instance of the class Dog,. how can you access the ancestor method move in Vertebrate so it prints out the string "move";
sethu chiyan
Greenhorn

Joined: Apr 05, 2005
Posts: 10
Hi,


class Vertibrate
{
public void move()
{
System.out.println("Move");
}

}

class Mammal extends Vertibrate
{
public void move()
{
super.move();
System.out.println("Walks");
}
}

class Dog extends Mammal
{
public void move()
{
super.move();
System.out.println("Walks on paws");
}
}

public class Mobile
{
public static void main(String[] args)

{
Dog _dog = new Dog();
_dog.move();
}
}

I have tried in this way, the o/p is:
Move
Walks
Walks on paws

Anyway I know this is not the exact answer what you expect,but i know we cannot use super.super.move();

Still am waiting for Gi's response.. pl guide me 2.

with regards,
Chiyan
Kalyani Marathe
Ranch Hand

Joined: Apr 06, 2005
Posts: 72
I thought this way. Check the code. I just made method static and assigned Vertebrate ref an instance of Dog.
class Vertibrate
{
public static void move()
{
System.out.println("Move");
}

}

class Mammal extends Vertibrate
{
public static void move()
{
//super.move();
System.out.println("Walks");
}
}

class Dog extends Mammal
{
public static void move()
{
//super.move();
System.out.println("Walks on paws");
}
}

public class Mobile
{
public static void main(String[] args)

{
Vertibrate ver = new Dog();
ver.move();
}
}
Tejal Modi
Greenhorn

Joined: May 04, 2000
Posts: 3
Hi Kal,
u r xactly correct.
with regards,
Chiyan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance
 
Similar Threads
Inheritance , dynamic binding?
over loaded methods??
Inheritance
Help sought in Overriding?
What is a class and object?