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

please just simplify stem out printint 2) class Parentclass int sum( int a, int

ID: 3736575 • Letter: P

Question

please just simplify

stem out printint 2) class Parentclass int sum( int a, int b, nt c return a+b+c; )( int sum(int a,int b) return a+b; class Childclass extends Parent classt public childclass() (x-1e int sum(int a, int b) return a+b+1; class Testi public static void main(String argstl ParentClass penew Childclass); System.out printin(p.sum(5,5,5)); System.out.printin(p. sum(5,5)): System.out.println(p.x); 3) class Person t public Person) f this("hil") public Person(String str) f System.out.println("I am " str); public class who extends Person f this("I am Tony"); public Who(String str) t public who) ( super (str); System.out.println("How do you do?");

Explanation / Answer

Here we have two complete questions 2 and 10

2) Output:

15

10

0

Explanation: Here although we have inheritance example written where ChildClass extends ParentClass but in Test class we have created object of ParentClass and hence all the methods and variable will be called of this class itself

Hence when we have

System.out.println(p.sum(5,5,5));

We are calling sum function of ParentClass having three arguments and which is returning sum all three values hence 5+5+5                               

System.out.println(p.sum(5,5));              

We are calling sum function of ParentClass having two arguments and which is returning sum all three values hence 5+5               

System.out.println(p.x);

Here we are accessing the instance variable of ParentClass whose value is 0.

10 ) Output: Reset 1

Explanation: Here we are taking input from user as 2 1

So first we have ind = sc.nextInt() which will read the int value entered which is 2

Then we have another value 1 which will be read by num = sc.nextInt().

So now we have

ind = 2

num = 1

In try block we have

x[ind] = num

i.e. x[2] = 1;

And then we are printing Reset x[ind]

which means Reset x[2]

Hence Reset 1