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

Questions 2-4 refer to the following classes public class Thing private int valu

ID: 3840826 • Letter: Q

Question

Questions 2-4 refer to the following classes public class Thing private int value; public Thing value 95; public string tostring return value public class cog extends Thing private int num; public cog num 85; public String to String return super .tostring numi 2. Which of the following is true? a. Cog can access any public methods in Thing. b. The toString in Cog is the same as the toString in Thing. c. Cog has access to all variables in Thing. d. Cog cannot access any methods in Thing. e. Thing can access all public methods in Cog 3. What is output by running the following code? Cog y new Cog system. out println (y): a. 85 b. 95 c. 85 95 d. 95 85 e. 85 85 Term 2 Unit 7 Week 10 yersinn 1

Explanation / Answer

2. Which of the following is true?
a. Cog can access any public method in Thing.
Answer: True. public method can be accessed

b. The toString in Cog is the same as the toString in Thing
Answer: False . Cog toString method print both value & num whereas Thing toString prints only value.

c. Cog has access to all variables in Thing.
Answer. False. All Thing variable i.e. value is private & cannot accessed

d. Cog cannot access any methods in Thing.
Answer. False. Only public & protected methods can be accessible.

e. Thing can access all public methods in Cog.
Answer: True. public method can be accessed

3. What is output by running the following code?

Cog y=new Cog();
System.out.println(y);

a. 85 b. 95 c. 85 95 d. 95 85 e. 85 85

Answer: d. 95 85
Explaination: super.toString() method print 95 & concatinate with num=85.