Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134457963
Author: GADDIS
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 9.2, Problem 9.4CP

Explanation of Solution

Output of the given program:

// Class definition

public class Sample {

// Main method

public static void main(String[] args)

{

// Create object for subclass

Sky object= new Sky();

}

// Superclass definition

public class Ground

{

// Constructor

public Ground()

{

// Display the statement

System.out.println("You are on the ground.");

}

}

// Subclass definition

public class Sky extends Ground

{

// Constructor

public Sky()

{

// Display the statement

System.out.println("You are in the sky.");

}

}

}

In the above program,

  • There are two classes,
    • “Ground” is the superclass and “Sky” is the subclass.
  • In “Ground” superclass,
    • The constructor “Ground” is created and the statement which is to be printed is given...

Blurred answer
Students have asked these similar questions
Consider the following three Java classes: public abstract class Toy {public void makeNoise() { System.out.println("DEFAULT SOUND"); }} public class Doll extends Toy {public void makeNoise() { System.out.println("Mama!"); }}public class ToyRobot extends Toy {private int volume; public ToyRobot() { this.volume = 5; } public void makeNoise() { System.out.println("BEEP"); } public int getVolume() { return volume; } public void setVolume(int volume) { this.volume = volume; }} Given these classes, determine what will be printed when each of the code snippets below are copied into the following main method at the indicated location. public static void main(String[] args) { Toy toy; Doll doll; ToyRobot robot1; ToyRobot robot2; doll = new Doll(); robot1 = new ToyRobot(); robot2 = robot1; toy = robot1; // INSERT CODE HERE. } A) doll.makeNoise();                           ["", "", "", ""]            B) toy.makeNoise();                           ["", "", "", ""]            C)…
There is a class hierarchy that includes three classes: class Animal {    protected int age;    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }}class Pet extends Animal {    protected String name;    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }}class Cat extends Pet {        protected String color;    public String getColor() {        return color;    }    public void setColor(String color) {        this.color = color;    }} Given the following object: Pet cat = new Cat(); Select all invalid method invocations.
**Python code** Write a class definition line and a one line docstring for the class Dog. Write an __init__ method for the class Dog that gives each dog its own name and breed. Test this on a successful creation of a Dog object.>>> import dog>>> sugar = dog.Dog('Sugar', 'border collie')>>> sugar.name'Sugar'>>> sugar.breed'border collie'

Chapter 9 Solutions

Starting Out with Java: Early Objects (6th Edition)

Ch. 9.4 - When a class member is declared as protected, what...Ch. 9.4 - What is the difference between private members and...Ch. 9.4 - Why should you avoid making class members...Ch. 9.4 - Prob. 9.14CPCh. 9.4 - Why is it easy to give package access to a class...Ch. 9.6 - Look at the following class definition: public...Ch. 9.6 - When you create a class, it automatically has a...Ch. 9.7 - Recall the Rectangle and Cube classes discussed...Ch. 9.8 - Prob. 9.19CPCh. 9.8 - If a subclass extends a superclass with an...Ch. 9.8 - What is the purpose of an abstract class?Ch. 9.8 - If a class is defined as abstract, what can you...Ch. 9.9 - Prob. 9.23CPCh. 9.9 - Prob. 9.24CPCh. 9.9 - Prob. 9.25CPCh. 9.9 - Prob. 9.26CPCh. 9.9 - Prob. 9.27CPCh. 9.9 - Prob. 9.28CPCh. 9 - In an inheritance relationship, this is the...Ch. 9 - In an inheritance relationship, this is the...Ch. 9 - This key word indicates that a class inherits from...Ch. 9 - A subclass does not have access to these...Ch. 9 - This key word refers to an objects superclass. a....Ch. 9 - In a subclass constructor, a call to the...Ch. 9 - The following is an explicit call to the...Ch. 9 - A method in a subclass that has the same signature...Ch. 9 - A method in a subclass having the same name as a...Ch. 9 - These superclass members are accessible to...Ch. 9 - Prob. 11MCCh. 9 - With this type of binding, the Java Virtual...Ch. 9 - Prob. 13MCCh. 9 - Prob. 14MCCh. 9 - Prob. 15MCCh. 9 - Abstract classes cannot ___________. a. be used as...Ch. 9 - You use the __________ operator to define an...Ch. 9 - Prob. 18MCCh. 9 - Prob. 19MCCh. 9 - You can use a lambda expression to instantiate an...Ch. 9 - True or False: Constructors are not inherited.Ch. 9 - True or False: in a subclass, a call to the...Ch. 9 - True or False: If a subclass constructor does not...Ch. 9 - True or False: An object of a superclass can...Ch. 9 - True or False: The superclass constructor always...Ch. 9 - True or False: When a method is declared with the...Ch. 9 - True or False: A superclass has a member with...Ch. 9 - True or False: A superclass reference variable can...Ch. 9 - True or False: A subclass reference variable can...Ch. 9 - True or False: When a class contains an abstract...Ch. 9 - True or False: A class may only implement one...Ch. 9 - True or False: By default all members of an...Ch. 9 - // Superclass public class Vehicle { (Member...Ch. 9 - // Superclass public class Vehicle { private...Ch. 9 - // Superclass public class Vehicle { private...Ch. 9 - // Superclass public class Vehicle { public...Ch. 9 - Write the first line of the definition for a...Ch. 9 - Look at the following code, which is the first...Ch. 9 - Write the declaration for class B. The classs...Ch. 9 - Write the statement that calls a superclass...Ch. 9 - A superclass has the following method: public void...Ch. 9 - A superclass has the following abstract method:...Ch. 9 - Prob. 7AWCh. 9 - Prob. 8AWCh. 9 - Look at the following interface: public interface...Ch. 9 - Prob. 1SACh. 9 - A program uses two classes: Animal and Dog. Which...Ch. 9 - What is the superclass and what is the subclass in...Ch. 9 - What is the difference between a protected class...Ch. 9 - Can a subclass ever directly access the private...Ch. 9 - Which constructor is called first, that of the...Ch. 9 - What is the difference between overriding a...Ch. 9 - Prob. 8SACh. 9 - Prob. 9SACh. 9 - Prob. 10SACh. 9 - What is an. abstract class?Ch. 9 - Prob. 12SACh. 9 - When you instantiate an anonymous inner class, the...Ch. 9 - Prob. 14SACh. 9 - Prob. 15SACh. 9 - Employee and ProductionWorker Classes Design a...Ch. 9 - ShiftSupervisor Class In a particular factory, a...Ch. 9 - TeamLeader Class In a particular factory, a team...Ch. 9 - Essay Class Design an Essay class that extends the...Ch. 9 - Course Grades In a course, a teacher gives the...Ch. 9 - Analyzable Interface Modify the CourseGrades class...Ch. 9 - Person and Customer Classes Design a class named...Ch. 9 - PreferredCustomer Class A retail store has a...Ch. 9 - BankAccount and SavingsAccount Classes Design an...Ch. 9 - Ship, CruiseShip, and CargoShip Classes Design a...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage