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

1) The Counter class doesu\'t have a constrictor. Why doesn\'t it need onc? 2) T

ID: 3706102 • Letter: 1

Question

1) The Counter class doesu't have a constrictor. Why doesn't it need onc? 2) The Counter class doesn't have a main. Why doesn't it need o 3) How do we know ModNCounter inhents trom Counter (what is the keyword)? 4) Which method is the constructor inside ModNCounter'class? 5) Is cyclelength vatiable visible to the parent Counter class? 6) What happens when we call value and reset methods for ModNCounter since it is not detined in 7) What happens when we call increment and reset methods ?or ModNCounter2 since t s not defined in ModNCounter2? 8) Does decrement exist inside Counter? 9) Does increment's behavior change for DecrementableCounter? 10) Where is tostring being inherited from-

Explanation / Answer

Below are your answers: -

public ModNCounter ( int n) {

                cycleLength = n;

}

5 No, parent class cannot access child class variables. As cycleLength variable is of ModNCounter class which is a child class and Counter is parent class, So Counter cannot access the cycleLength variable.

6. Value and reset methods are not in ModNCounter class but these are defined publically in Counter class. As ModNCounter class inherits the Counter class, So ModNCounter class has access of these methods. So when value is called for ModNCounter , it returns the value of the present counter value, and reset method will reset the counter value to 0.

7. increment and reset methods are not in ModNCounter2 class but these are defined publically in Counter class. As ModNCounter2 class inherits the Counter class, So ModNCounter2 class has access of these methods. So when increment is called for ModNCounter2 , it increments the value of the present counter value, and reset method will reset the counter value to 0.

8. No decrement method is there in class DecrementableCounter which is a child class of Counter class. As parent class cannot access the method of child class, So decrement does not exist in Counter.

9. No, increment behavior does not change for DecrementableCounter class because, increment method is not overridden and we are just calling it in decrement() method, which does not change the behavior of increment method.

10. toString method is present in Object class( java.lang.Object) . Every class in Java inherits the Object class. toString() method is thus inherited from Object class.