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

Student Name: Honor Pledge: Each of the following five exercises is worth 2 poin

ID: 3881987 • Letter: S

Question

Student Name: Honor Pledge: Each of the following five exercises is worth 2 points Exercises Consider the following code. Implementations are not shown to save space. public Class aClass public boolean readFile (String s) //method1 public boolean setValue (int ) //method2 public Class anotherClass extends aClass( public boolean readFile (String s): //method3 public boolean setValue (double d): //method4 1. Which method is executed if I instantiate an object and do the following aClass obj e anotherClass obj.setValue(3) 2. Which method is executed if I do the following: anotherClass obj = new anotherClass(); obj.setValue(3.0) 3. Why does Java refuse to accept the following code? aClass obj new anotherClass obj.setValue(3.0) 4. Based only on the code shown above, which of the four methods can include the super keyword? 5. If they exist, give examples of overloading and overriding in the code above.

Explanation / Answer

1.

public boolean setValue(int i);

function is called beacuse the parameter type in function is integer type and aClass object is points to anotherclass

memory.

2.

public boolean setValue(double i);

function is called because the parameter type in function is double type and obj points to anotherclass memory

3.

public boolean setValue(int i);

function is expecting integer type value but passed value is double type so parameter type mismatch occurs so it refuse to accept the code

4.

super() keyword included in anotherClass of

public boolean readFile(String s);

beacuse two classes have declartion for readFile(),when you tried to call readFile function from the object of anotherclass it hides the function of base class i.e readFile() of aClass; so if you want to call the readfile() of another class you need to include super() keyword in anotherClass's readFile() function, this mechanism is called the function overriding;

5.

function over loading examples are

public boolean setValue(int i); and public boolean setValue(double i)

function over loading means function name is same but parameter list in function is different.

above function name is setValue() two classes have same name functions. But differs in paramater list one class

have int type parameter another have double type parameter is expecting when you called.

function overriding examples are in above code

In two classes base class(aClass) and derived class(anotherClass) have the function with same name with

public boolean readFile(String s);

when you tried to call base class readFile() function it hides and calls the derived class readFile() function,

so this opeartion is called funcction overridding.