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
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
public class Main{    public static void main(String args[])    {        Main m = new Main();        m.go();    }        public void go()    {        Customer c = new Customer("Tom", "Smith");        Order o = new Order(c);        o.addItem(new Item("Greeting Card", 1.50, 1));        o.addItem(new Item("Baseball Glove", 54.00, 1));        o.addItem(new Item("Notebook", 2.50, 3));                System.out.println(o);    }}
class Param3 { public int x; private void increase(int p) { x = x*p; } public void calculateX(int y) { increase(y); } public int getX() { return x; } } // in another class Param3 q3 = new Param3(); q3.x = 5; q3.calculateX(7); System.out.println(q3.getX()); what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?
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