Concept explainers
Look at the following classes:
public class Ground
{
public Ground()
{
System.out.println(“You are on the ground.”);
}
public Ground(String groundColor)
{
System.out.println(“The ground is ” + groundColor);
}
}
public class Sky extends Ground
{
public Sky()
{
System.out.println(“You are in the sky.”);
}
public Sky(String skyColor)
{
super(“green”);
System.out.println(“The sky is “ + skyColor);
}
}
What will the following
public class Checkpoint
{
public static void main(String[] args)
{
Sky object = new Sky(“blue”);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
SURVEY OF OPERATING SYSTEMS
Concepts Of Programming Languages
BASIC BIOMECHANICS
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- public class First { public String name() { return "First"; } } public class Second extends First { public void whoRules() { System.out.print(super.name() + " rules"); System.out.printin(" but " + name() + " is even better"); } public String name() { return "Second"; } } public class Third extends Second { public String name() { return "Third"; } } Consider the following code segment. * SomeType1*/ varA = new Second(); * Some Type2*/ varB = new Third(); varA.whoRules(); varB.whoRules(); Which of the following could be used to replace /* SomeType1*/ and /* SomeType2*/ so that the code segment will compile without error?arrow_forwardclass 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?arrow_forwardpackage debugging; public class BeanCounter {public static int beanCount = 0;} public class Bean {public Color beanColor;public String description;public Bean(Color beanColor, String description){this.beanColor = beanColor;this.description = description;}} public class Color {double[] rgb;double saturation;public Color(double[] rgb, double saturation){this.rgb = rgb;this.saturation = 0.0;}} public class Debugging { /*** @param args the command line arguments*/public static void main(String[] args) {BeanCounter bc = new BeanCounter();double[] redGreenBlue = {22.3d, 41.7d, 202.57d};Color c = new Color(rgb, 22.44+0.05, 15.78, 79.53, 252.04);++BeanCounter.beanCount;Bean b = new FavaBean(c); // New bean created!bc.beanCount++;}} 1. Remove the errors, warnings and mistakes that are in the source code. 2. Modify the code so that: •one bean is created •one bean is counted •there is only one line in the main methodarrow_forward
- public class Pet { protected String name; protected int age; public void setName(String userName) { name = userName; } public String getName() { return name; } public void setAge(int userAge) { age = userAge; } public int getAge() { return age; } public void printInfo() { System.out.println("Pet Information: "); System.out.println(" Name: " + name); System.out.println(" Age: " + age); } } import java.util.Scanner;public class PetInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Pet myPet = new Pet(); Cat myCat = new Cat(); String petName, catName, catBreed; int petAge, catAge; petName = scnr.nextLine(); petAge = scnr.nextInt(); scnr.nextLine(); catName = scnr.nextLine(); catAge = scnr.nextInt(); scnr.nextLine(); catBreed = scnr.nextLine(); // TODO: Create generic pet (using petName, petAge) and then…arrow_forwardQuestion 13 What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle= = new Plane(); myVehicle.drive(); } Driving vehicle syntax error Flying plane Driving vehicle Flying plane }arrow_forwardpublic class SeperateDuplicates { public static void main(String[ args) { System.out.printIn(seperateDuplicatesChars("Hello")); System.out.printin(seperateDuplicatesChars ("Bookkeeper"')); System.out.printin(seperateDuplicatesChars("Yellowwood door"')); System.out.printin(seperateDuplicatesChars("Chicago Cubs")); */ public static String seperateDuplicatesChars(String str) { //To be completed } }arrow_forward
- public class Secret private int x; private static int y; public static int count; public int z; public Secret () } X ?t = 2 { public Secret (int a) } { public Secret (int a, int b) } { public String toString() return ("x = " count = " + count); { public static void incrementY () { { 54. How many constructors are present in the class definition above? C. 2 d. 3 b. 1 55. What does the default constructor do in the class definition above? a. Sets the value of x to 0 c. Sets the value of x to 0 and the value of z to 1 d. There is no default constructor. b. Sets the value of z to 1 56. Based on the class definition above, which of the following statements is illegal? Secret.incrementY (); b. Secret.count++3B a. c. Secret. 2++; d. None of these 13arrow_forward// Simulates a simple car with operations to drive and check the odometer.public class SimpleCar { // Number of miles driven private int miles; public SimpleCar(){ miles = 0; } public void drive(int dist){ miles = miles + dist; } public void reverse(int dist){ miles = miles - dist; } public int getOdometer(){ return miles; } public void honkHorn(){ System.out.println("beep beep"); } public void report(){ System.out.println("Car has driven: " + miles + " miles"); } }arrow_forwardpublic class A { public void funl () { System.out.println ("Al"); } public class B extends A { @Override public void funl () { super.fun1 () ; System.out.println ("B1"); public void fun2 () { System.out.println ("B2"); public class C extends B { @Override public void funl () { System.out.println ("C1");arrow_forward
- public class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…arrow_forwardConsider the following class definitions: public class Thing {public void string_method(String word) {word = word.substring(word.length() - 1);System.out.print(word);} }public class Thing2 extends Thing {public void string_method(String word) {super.string_method(word);System.out.print(word.substring(0,1));}} The following code segment appears in a class other than Thing or Thing2 Thing2 thing = new Thing2();thing.string_method("Tacky"); What is printed as a result of running the code segment? Group of answer choices yT yy Index Out of Bounds Error TT TackyTackyarrow_forwardFind the error(s) in the following class definition: public class Circle private double radius; public double setRadius(double a) { radius = a; public void getRadius() { return radius;arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT