Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Expert Solution & Answer
Book Icon
Chapter 2, Problem 11R

Explanation of Solution

Output of the code:

Create a main class Maryland that extends the State class and it includes printMe() to display the respective header in console.

// Create a class Maryland

public class Maryland extends State

{

  // Null constructor

  Maryland( )

  {

  }

  // Create a method

  public void printMe( )

  {

  System.out.println("Read it.");

  }

Create a main() function and create the objects for the class using new keyword and call the method printMe() to display the respective header.

  // Main function

  public static void main(String[ ] args)

  {

  // Create the objects for classes

  Region east = new State( );

  State md = new Maryland( );

  Object obj = new Place( );

  Place usa = new Region( );

/* Call the method printMe() using state class object.*/

  md.printMe( );

  // Call the method printMe() using object

  east.printMe( );

  // Call the method printMe() in Place class

  ((Place) obj).printMe( );

  //Assign the state class object to object class

  obj = md;

  // Call the method printMe() in maryland class

  ((Maryland) obj).printMe( );

  //Assign the place class object to object class

  obj = usa;

  // Call the method printMe() in place class

  ((Place) obj).printMe( );

  //Assign the state class object to place class

  usa = md;

  // Call the method printMe() in place class

  ((Place) usa).printMe( );

  }

}

Create a class State that extends the class Region and includes a method printMe() to display the header.

// Create a class that extends the Region

class State extends Region

{

  //Null constructor

  State( )

  {

  }

  //Create a method

  public void printMe( )

  {

  //Display the header

  System.out.println("Ship it.");

  }

}

Create a class Region that extends the class Place and includes a method printMe() to display the header...

Blurred answer
Students have asked these similar questions
X2, Y2------1.
class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x 0; %3D this.y = 0; } %3D } class Overload_methods { public static void main(String args[]) { overload obj int a = 2; double b - 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + } = new overload(); + obj.y); } #3Run the code
For the following four classes, choose the correct relationship between each pair. public class Room ( private String m type; private double m area; // "Bedroom", "Dining room", etc. // in square feet public Room (String type, double area) m type type; m area = area; public class Person { private String m name; private int m age; public Person (String name, int age) m name = name; m age = age; public class LivingSSpace ( private String m address; private Room[] m rooms; private Person[] m occupants; private int m countRooms; private int m countoccupants; public LivingSpace (String address, int numRooms, int numoccupants) m address = address; new int [numRooms]; = new int [numOceupants]; m rooms %3D D occupants m countRooms = m countOccupants = 0; public void addRoom (String type, double area)
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education