Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Problem 0.15: A car dealership needs a program to store information about ca

ID: 3772244 • Letter: F

Question

For Problem 0.15: A car dealership needs a program to store information about cars for sale. each car they want to keep track of: the number of doors (2, 4, or 5), whether the car has air conditioning, and its average number of miles per gallon. Which of the following is the best design? 1. Use one class, Car, which has three instance variables int numDoors, boolean hasAir, and double milesPerGallon. 2. Use four unrelated classes: Cars, Doors, Airconditioning, and 3. Use a class Car, which has three subclasses: Doors, AirConditioning, and 4. Use three classes: Doors, AirConditioning, and MilesPerGallon each MilesPerGallon. MilesPerGallon. with a subclass Car Problem 0.16%: Assume that dlas A extends class B, which extends class C. Also all he three Problem 0.16: Assume that class A extends class B, which extends class C. Also all the three classes implement the method test). How can a method in the subclass A invoke the test () method defined in class c (without creating a new instance of class C)? Select the one correct answer. 1.test); 2.super.test); 3.super.super.test); 4. It is not possible to invoke test() method defined in C from a method in A Problem 0.17: The following is an example of public static int min(int a, int b, int c) ( /I code here... public static int min(int a, int b, int c, int d)f /I code here... 1. Polymorphism 2. Overriding methods 3. Overloading methods 4. Casting

Explanation / Answer

Solution for Problem 0.15:

Option 1 is the best design.

Make Car as a base class which can be used for any model and make of the car.
Features of car like number of doors, availability of air conditioning, number of miles per gallon are designed as instance variables of class Car.

Hence the correct option is option(1).

---------------------------------------------------------------------------------------------------------------------
Solution for Problem 0.16:

Option 1, test() is used to call 'test' method by any of the other non-static methods defined in the same class.

Option 2, super.test() is used by a method in class A to call the test method of its immediate base class which is class B.

Option 3, super.super.test() is not a valid syntactical statement.

Option 4, Method in class A can't directly invoke test method of class C. In the indirect way, Class A first invokes test method of Class B first and method test of class B invokes test method of class C.

Hence, the correct option is option(4).

----------------------------------------------------------------------------------------------------------------------
Solution for Problem 0.17:

Option 1, Polymorphism is one Object Oriented Programming(OOP) feature which means same form but different meaning. Overloading and Overriding uses the concept of Polymorphism.

Option 2, Overriding is the implementation of Polymorphism concept which means same method (same name,same return type, same arguments) defined in multiple classes that are created using inheritence concept.

Option 3, Overloading is the implementation of polymorphism concept which means same method (same name,same return type, different number of arguments) defined in the same class.

Option 4, Casting is the process of converting data from one data type to another data type.

The piece of code provided is an example of Method Overloading. Hence the correct option is option(3).

---------------------------------------------------------------------------------------------------------------------
Solution for Problem 0.18:

Printing object s1 of class Student does the following sequence of actions:
1. First a check is made whether definition of toString() exists locally or not. If it exists, it prints the corresponding statements. If not exists , predefined method toString() method gets executed and prints the value of following pattern:

A@182f0db

First part represents type of the object.
Second part represents hashcode of the object.

Hence the correct option is option(4)
---------------------------------------------------------------------------------------------------------------------
Solution for Problem 0.19:

Correct syntax of boolean expression to see whether the person's age is between 60 and 65 both inclusive is:
(age >= 60 && age <=65)

Hence, the correct option is option(4).

---------------------------------------------------------------------------------------------------------------------
Solution for Problem 0.20:

Object 'a' of class Animal which is the base class was instantiated with child class Dog, object 'a' will get reference to methods of class 'Dog' and so statement a.printX() invokes the method of class Dog. Output will be 20.

Hence the correct option is option(2).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote