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

1. What is the difference between overriding a method and overloading a method n

ID: 3915223 • Letter: 1

Question

1. What is the difference between overriding a method and overloading a method name? 2. Suppose the class SportsCar is a derived class of a class Automobile. Suppose also that the class Automobile has private instance variables named speed, manufacturer, and numberOfCylinders. Will an object of the class SportsCar have instance variables named speed, manufacturer, and numberOfCylinders? 3. Suppose the class SportsCar is a derived class of a class Automobile, and suppose also that the class Automobile has public methods named accelerate and addGas. Will an object of the class SportsCar have methods named accelerate and addGas? If so, do these methods have to perform the exact same actions in the class SportsCar as in the class Automobile? 4 Can a derived class directly access by name a private instance variable of the base class? 5. Can a derived class directly invoke a private method of the base class? 6.Suppose s is an object of the class Student. Based on the inheritance diagram in lesson, where will you find the definition of the method hasSameName, used in the following invocation? Explain your answer. Student other- new Student("Joe Student", 777 if (s.hasSameName(other) System.out.println("Wow!"); 7. Suppose s is an object of the class Student. Based on the inheritance diagram in lesson, where will you find the definition of the method used in the following invocation? Explain your answer. s.setStudentNumber(1234);

Explanation / Answer

Q1

Overloading means that we are using same method name but with different parameters

Overriding means that we are using the same method signature but are implementing it in a different in a subclass or child class

Q2

No the subclass doesn't inherit the private variables but inherits protected and public variables

Q3

Yes they are present in sports class.

Q4

No it can't access it directly

Q5

No

Q6,7

The definitions will be present in the parent class of the student from which it derives