Consider the following class declaration: 1 public class Map 2 { 3 private String city = "Seattle"; 4 5 public void printCityName(String city) 6 { 7 System.out.println("The name of the city is " + city); 8 } 9 } What will be printed if we invoke printCityName("Boston")? Justify your answer
Q: copying, each reference variable refers to its own object. shallow 51. In а. с. method b. deep d.…
A: Note: Since the Question is multipart we are advised to do only first three parts. Kindly post other…
Q: The base class Pet has protected fields petName, and petAge. The derived class Cat extends the Pet…
A: The main() method of a program that makes instances of the Pet and Cat classes and prints their…
Q: What is the output of the code on the right?
A: Java is an object oriented programming language.
Q: 58. How many finalizers can a class have? - a. C. 2 d. Any number b. 1 59. Which of the following…
A: Note: This is a multiple-question-based problem. As per company guidelines, only the first question…
Q: Write a compareTo () method for this Student class. public class Student { private String name;…
A: compareTo(): method is used to compare to objects inputs to this method is: the object that you have…
Q: public class Car { public void m1( { Sustem.Qut.printla("car 1"); } public void m2() { super.m1(); }…
A: answer is
Q: • Exercise # 1: Define a class Point that represents a point in 2 - D plane. The point has x and y…
A: Program Approach: Declaring the class Defining the constructor sets x, y coordinates Declaring the…
Q: public class Stadium extends baseStadium{ public int typeTicket; int floors; int seating;…
A: The code includes three classes: Stadium, ticket, and baseStadium, and one interface TicketService.…
Q: PlayerRoster.java:139: error: class, interface, or enum expected import java.util.Scanner;…
A: We need to rectify the errors in the given Java code.
Q: class Vehicle { String s = "This is my vehicle" ; } class Car extends Vehicle { String s = "This is…
A: Given java code :- class Vehicle{ String s = "This is my vehicle" ;}class Car extends Vehicle{…
Q: private: int x, у;
A: Corrected Program: #include<iostream.h> #include<conio.h> class Point { private: int…
Q: public class Car { public void horn() { System.out.println("Horn horn"); } } public class Ferrari…
A: NOTE - As per the guidelines we are allowed to solve only one question, please repost other parts as…
Q: class Time { private int hour; private int minute; private int second;…
A: The JAVA code is given below with output screenshot
Q: Identify errors if there is any & after identifying rewrite the code: public class Employce {…
A: Error Free Textual Code :- //The type Employee must be an abstract class to define a abstract…
Q: Consider the following class: 1 public class Student { 2 private int studentNumber; 3 private…
A: OOP or Object-Oriented Programming is a software model that is designed around data or objects…
Q: Question 1 public class Flat { private int noofRooms; private double area; private boolean seaView;…
A: public class Flat { private int noOfRooms; private double area; private boolean seaView;…
Q: 2. Complete the application below. public class CarApp { public static void main() { string color =…
A: ALGORITHM:- 1. Create a class CarApp with the variables defined in question. 2. Initialise a object…
Q: public void addRoom (String type, double area) m rooms [m countRooms] m countRooms++; = new Room…
A: IN this question we have to demonstrate the relationship between the following classes in java.
Q: ven the following class definition: class employee { public: employee(); employee(string,…
A: The code has given below
Q: I have the following code: public class Length { private int feet; private int inches; // Your code…
A: The given Java program is as follows: public class Length{private int feet;private int inches;//…
Q: What is printed? public class Puppy { private int puppyAge; private String puppyName; Puppy(String…
A: The correct answer is : (d) Run time error
Q: Analyze the code below and answer the questions that follows. class Shapes { public void identify ()…
A: OOP stands for Object Oriented Programming.
Q: Write a statement in ClassA to check out the accessibility of your variable. package package_02;…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: Write the equals method for the following class: B2. public class Car{ String color int number
A: Since the programming language has not been mentioned, I'd write the java code for the same.
Q: What is outpout?
A: In step 2, I have provided answer , then I have provided JAVA CODE along with CODE SCREENSHOT…
Q: Stairviewer public static void main(String (] args) // Step 2: Create a rectangle and draw it as the…
A: ANSWER: Draw Rectangle in C graphics: Draw rectangle for utilized Rectangle(). Directions of left…
Q: class Accumulator { private int total private String name; public Accummulator (string name ,…
A: It is defined as a programming language and a platform. Java is a high level, robust,…
Q: Question 6 Consider: class Bike { } private String color; public Bike() { } public Bike(String…
A: A constructor in Java is a special method that is used to initialize objects.
Q: Following is the class of Person: public class Person { private String Name; public…
A: Code:class PersonManagement{Â Â Â Â Person [] persons;Â Â public void set(Person[] persons) {Â Â…
Q: It is supposed to output the following: Expected output [15' 0"] [20' 6"] [17' 4"] [16' 4"] [17'…
A: public class Length { private int feet; private int inches; Length() { feet = inches = 0; }…
Q: tumLeft and turn Right methods that change the direction of the robot but not the location move…
A: public class Robot{ //declaring instance variables private String name; private int xPos; private…
Q: This class includes a constructor that begins on line 8; however, it contains an error. Describe the…
A: The following code :public class Author2 {3 private String name;4 private int numberOfAwards;5…
Q: What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle");…
A: Option A: Syntax error
Q: // Simulates a simple car with operations to drive and check the odometer. public class SimpleCar {…
A: Import Scanner class.Define the Main class.Define the main method.Create a Scanner object for…
Q: Consider the following class definition: class circle { public: void print() const; void…
A: The two classes given arecirclecylinderThe functions for the class circle:public: void print()…
Q: public class Father { public String name; public int age; // customer name Father(){…
A: Inheritance is the process of acquiring the base class properties/methods to the child class. Using…
Consider the following class declaration:
1 public class Map
2 {
3 private String city = "Seattle";
4
5 public void printCityName(String city)
6 {
7 System.out.println("The name of the city is " + city);
8 }
9 }
What will be printed if we invoke printCityName("Boston")? Justify your answer.
Step by step
Solved in 2 steps
- 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)public class StairViewer public static void main(String(] args) // Step 2: Create a rectangle and draw it as the // top step of the stair // location: (20, 10) // size: (20, 20) 18 // Step 3: Create a rectangle and draw it as the 19 // middle step of the stair 20 // location: below the top step, aligned on left // size: (40, 20) 21 22 23 24 // Step 4: Create a rectangle and draw it as the 25 // bottom step of the stair 26 // location: below the middle step, aligned on left // size: (60, 20) 27 28 29 30 } 31 32Question 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 }
- Public classTestMain { public static void main(String [ ] args) { Car myCar1, myCar2; Electric Car myElec1, myElec2; myCar1 = new Car( ); myCar2 = new Car("Ford", 1200, "Green"); myElec1 = new ElectricCar( ); myElec2 = new ElectricCar(15); } }public class Accumulator { private int total private String name; public Accummulator (string name , int total) { this .name = name; this .total=total; } } 3. In a main method, create an object of Accumulator with the name as "Mary" and total as 100.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 myVehicle.drive(); } } = new Plane(); syntax error Driving vehicle Flying plane Flying plane O Driving vehicle
- 5 points Save Answer QUESTION 4 What is printed? public class Puppy { private int puppyAge; private String puppyName; Puppy(String name){ puppyName = name ;} public void setAge( int age ) { puppyAge = ++age; } public int getAge(){ return puppyAge; } %3D public class TestPuppy{ public static void main(String []args) { Puppy myPuppy = new Puppy( "tommy" ); myPuppy.setAge( 2 ); System.out.print("Puppy's age is :" + myPuppy.getAge()); System.out.print(" %3D Name chosen is :" + myPuppy.puppyNname ); D Puppy's age is : 2 Name chosen is : tommy Puppy's age is : 3 Name chosen is : tommy O Syntax Error O Run Time Error Save All Answers Close Window Save and Submit - Save and Submit to save and submit. Click Save All Answers to save all answers. MacBook Pro 888 ES F6 F3 96 7QUESTION 9 Public Class Employee { public static int y; Private int age; Public Employee(0{ age=0;} public int get_age() { return age;} Public Class Test { public static void main(String[] args) { Employee q = new Employee(); q.y=2; Employee.y=10; System.out.println("y=" + q.y); a. What is the output of the following code? b. Insert a System.out.println() statement that prints out q's ageI have the following code: public class Length{private int feet;private int inches;// Your code goes here Length(){feet = inches = 0;} Length(int newFeet, int newInches){feet = newFeet;inches = newInches;} public int getFeet() { return feet; }public void setFeet(int newFeet) { feet = newFeet; } public int getInches() { return inches; }public void setInches(int newInches) { inches = newInches; } public Length add(Length otherLength){int newFeet = feet + otherLength.feet;int newInches = inches + otherLength.inches; if(newInches >= 12){newFeet++;newInches -= 12;} return (new Length(newFeet,newInches));} public Length subtract(Length otherLength){if(this.feet > otherLength.feet){int newFeet = feet - otherLength.feet;int newInches = inches - otherLength.inches;if(newInches < 0){newFeet--;newInches += 12;} return (new Length(newFeet,newInches));}else{int newFeet = otherLength.feet - feet;int newInches = otherLength.inches - inches;if(newInches < 0){newFeet--;newInches += 12;}…
- Question 6 Consider: class Bike { } private String color; public Bike() { } public Bike(String newColor) { color = newColor; } public Bike (Bike bike) { color = } bike.color; public String getColor() { } } return color; public void setColor(String newColor) { color = newColor; Bike bike1= new Bike(); = Bike bike2 new Bike("blue"); Bike bike3 = new Bike(bike2); bike2.setColor("green"); Bike bike4 = new Bike(bike2); Which of the following are correct? bike4.getColor() returns null bike4.getColor() return "blue" bike3.getColor() return "green" bike2.getColor() returns "blue" bike4.getColor() return "green" bike1.getColor() returns bike3.getColor() return null bike3.getColor() returns "blue" bike2.getColor() returns "green" bike1.getColor() returns null8. OOPS Theory #6 public class Car { public void horn() { System.out.println("Horn horn"); } } public class Ferrari extends Car { public void horn() { System.out.println("Ferarriiiiii"); } } public static void main(String[] args) { Ferrari ferrari = new Car(); ferrari.horn(); } Pick ONE option Horn horn Ferarriiii Cannot compile Runtime exception Clear Selection 9. OOPS Theory #7 In Java, we can achieve the abstraction by creating the blueprint of an object and only have abstract methods. What do we call this? Pick ONE option Interface Encapsulation Instance Protected Clear Selectionpublic 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…