Inheritance, Polymporhism, and Dynamic Dispatch Please answer the following questions about type conformance and dynamic binding.  Please copy/paste each table into your answer area, then fill in your answers in the tables for A, B and C. Here are some class definitions: public class Game{ public void players() { System.out.println(“1 or more”); } } public class Chess extends Game { public void boardSize() { System.out.println(“8 by 8”); }     public void players() { System.out.println(“2”); } } public class ThreeDChess extends Chess{     public void boardSize() {System.out.println(“7 levels”); }     public void hasMoveableBoard() { System.out.println(“true”); } } Assume that these statements have already executed: Game g = new Game(); Chess c = new Chess(); ThreeDChess t = new ThreeDChess(); Object og = g; Game gc = c; Game gt = t; // Add new statements here ONE AT A TIME A)  Complete the following table (copy/paste into your answer): Variable Static Type Dynamic Type og     gc     gt     B) Explain what would happen if each of the following statements were inserted ONE AT A TIME in the spot marked above. Complete the following table for each statement: Will the statement compile? If the answer is no, stop. If yes, what are the static and dynamic types of the variable declared? Statement Will it compile? (Y/N) If it compiles, static type? If it compiles, dynamic type? Game gx = gc;       Game gx = og;       Game gx = (Game)og;       Chess cx = (Chess)gt;       ThreeDChess tx = (ThreeDChess)gc; C) Finally, explain what would happen if each of the following statements were inserted ONE AT A TIME in the spot marked above. Answer the following questions for each statement: Will the statement compile? If yes, would the statement throw a ClassCastException? If no, then explain what output is shown Statement Compiles? Throws ClassCastException? Output? gc.players();       og.players();       t.players();       ((ThreeDChess)gc).hasMoveableBoard();

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

                     Inheritance, Polymporhism, and Dynamic Dispatch

Please answer the following questions about type conformance and dynamic binding.  Please copy/paste each table into your answer area, then fill in your answers in the tables for A, B and C.

Here are some class definitions:

public class Game{
public void players() { System.out.println(“1 or more”); }
}
public class Chess extends Game {
public void boardSize() { System.out.println(“8 by 8”); }
    public void players() { System.out.println(“2”); }
}
public class ThreeDChess extends Chess{
    public void boardSize() {System.out.println(“7 levels”); }
    public void hasMoveableBoard() { System.out.println(“true”); }
}

Assume that these statements have already executed:

Game g = new Game();
Chess c = new Chess();
ThreeDChess t = new ThreeDChess();

Object og = g;
Game gc = c;
Game gt = t;

// Add new statements here ONE AT A TIME

A)  Complete the following table (copy/paste into your answer):

Variable Static Type Dynamic Type
og    
gc    
gt    

B) Explain what would happen if each of the following statements were inserted ONE AT A TIME in the spot marked above. Complete the following table for each statement:

  1. Will the statement compile? If the answer is no, stop.
  2. If yes, what are the static and dynamic types of the variable declared?
Statement Will it compile? (Y/N)

If it compiles,
static type?

If it compiles,
dynamic type?
Game gx = gc;      
Game gx = og;      
Game gx = (Game)og;      
Chess cx = (Chess)gt;      
ThreeDChess tx = (ThreeDChess)gc;

C) Finally, explain what would happen if each of the following statements were inserted ONE AT A TIME in the spot marked above. Answer the following questions for each statement:

  1. Will the statement compile?
  2. If yes, would the statement throw a ClassCastException?
  3. If no, then explain what output is shown
Statement Compiles? Throws ClassCastException? Output?
gc.players();      
og.players();      
t.players();      
((ThreeDChess)gc).hasMoveableBoard();    
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education