Question

Consider the below excerpt of a Java program. Fill in each of the blanks (____) with...

Consider the below excerpt of a Java program. Fill in each of the blanks
(____) with the value returned by the method call that is given after the
== operator.
              
public class AShape
{   
   public int match(AShape p)        { return 1; }
}
public class Rectangle extends AShape
{  
   public int match(AShape p)        { return 2; }
   public int match(Rectangle p)   { return 3; }
}
public class Square extends Rectangle
{  
   public int match(Rectangle p)   { return 4; }
   public int match(Square p)        { return 5; }
}
/* .. */
AShape        a1 = new AShape();
AShape        a2 = new Rectangle();
AShape        a3 = new Square();
Rectangle r1 = new Rectangle();
Rectangle r2 = new Square();
Square        s1 = new Square();

____ == a3.match(r1)
____ == r1.match(a3)
____ == a2.match(a2)
____ == a2.match(a1)
____ == a1.match(a2)

____ == s1.match(s1)
____ == r2.match(r1)
____ == r1.match(r2)
____ == r2.match(a3)
____ == a3.match(r2)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class AShape
{   
public int match(AShape p) { return 1; }
}
public class Rectangle extends AShape
{
public int match(AShape p) { return 2; }
public int match(Rectangle p) { return 3; }
}
public class Square extends Rectangle
{
public int match(Rectangle p) { return 4; }
public int match(Square p) { return 5; }
}
/* .. */
AShape a1 = new AShape();
AShape a2 = new Rectangle();
AShape a3 = new Square();
Rectangle r1 = new Rectangle();
Rectangle r2 = new Square();
Square s1 = new Square();

2 == a3.match(r1)
2 == r1.match(a3)
2 == a2.match(a2)
2== a2.match(a1)
1== a1.match(a2)
5== s1.match(s1)
4 == r2.match(r1)
3 == r1.match(r2)
2 == r2.match(a3)
2== a3.match(r2)

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Consider the below excerpt of a Java program. Fill in each of the blanks (____) with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Modify the code to create a class called box, wherein you find the area. I...

    JAVA Modify the code to create a class called box, wherein you find the area. I have the code in rectangle and needs to change it to box. Here is my code. Rectangle.java public class Rectangle { private int length; private int width;       public void setRectangle(int length, int width) { this.length = length; this.width = width; } public int area() { return this.length * this.width; } } // CONSOLE / MAIN import java.awt.Rectangle; import java.util.Scanner; public class Console...

  • In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle....

    In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle. Review Lab 5 before completing this lab and retrieve the MyRectangle class that you completed for this lab, since you will need it again in this lab. Before starting this lab, edit your MyRectangle class in the following way: • change the declaration of your instance variables from private to protected This will enable access of these variables by your MySquare subclass. Here is...

  • JAVA question: Please see the code posted below and improve it so it allows for: 1.new...

    JAVA question: Please see the code posted below and improve it so it allows for: 1.new aircraft are entered [new objects] 2.these objects are automatically be assigned their unique IDs [unique ID linked to a static class variable?] 3.will not be automatically given airport codes [initialise airportCode as null in the constructor] 4.assign an airport code to each new aircraft [an object method?] The code: class Aeroplane { static int planeCount = 0; static int codeGenerator = 0; int uniqueID...

  • I have to create a java graphics program which will draw 10 rectangles and 10 ellipses...

    I have to create a java graphics program which will draw 10 rectangles and 10 ellipses on the screen. These shapes are to be stored in an arrayList. I have to do this using 6 different class files. I am not sure whether I successfully created an ellipse in the Oval Class & also need help completing the print Class. I need someone to check whether my Oval Class is correct (it successfully creates an ellipse with x, y, width,...

  • Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks...

    Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...

  • In Java Create a testing class that does the following to the given codes below: To...

    In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • Use the program listing below to answer the questions that follow. Note that this is not...

    Use the program listing below to answer the questions that follow. Note that this is not a working program. The intent of the assignment is for you to apply your knowledge of structural testing to answer the accompanying testing questions. 1. public static void main(String[] args) { 2. double a1 = 1.0; 3. double a2 = 2.0; 4. double a3 = 3.0; 5. if (cl) { 6. r1 = rate * 1.1; 7. r2 = rate * 2.1; 8. }...

  • fill in the blanks with java code The following code implements a Java timer that looks...

    fill in the blanks with java code The following code implements a Java timer that looks like the application below. . Once the application starts it keeps counting seconds until it is terminated. Timer (sec): 20 You are given a partial implementation of the program. Fill out the missing code to complete the program. import java.awt.*; import java.awt.event.; import java.util."; import javax.swing. *; import javax.swing. Timer; * This program shows a timer that is updated once per second. public class...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT