In this set of assignments


In this set of assignments you will exercise the object-oriented concepts of inheritance and polymorphism. Both questions are required.

This question is to be answered on “paper”. Please type your answer to each subpart into a word document (week7-q1.doc) and submit.

Consider the following definitions of classes.

public class Pet { }

public class Robot extends Pet {
public boolean strongerThan( Robot other ) {…}


public class HousePet extends Pet {
public String vetsName() {…}

public class Dog extends HousePet {
public Object fetch() {}


Note that in the code above the … indicates where there may be extra code which hasn’t been shown.

Given the following variable definitions

Pet pet;
HousePet housepet;
Dog dog;
Robot robot;

Indicate below which one of the following code snippets are legal and which are not legal by writing yes or no next to each code snippet. View each snippet in isolation (independent of other code snippets).

pet = dog;
dog = housepet;
housepet = (Dog) robot;
((Dog) pet).fetch();
robot.strongerThan((Robot) pet);

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount