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

Java Question 1: Describing Inheritance Rules In your own words, describe the fo

ID: 3673242 • Letter: J

Question

Java

Question 1: Describing Inheritance Rules

In your own words, describe the following:

What are the rules for accessing public, private, and protected variables declared in a parent class from the child class?

What are the two uses of the super keyword?

When and how do you override a method?

Question 2: Design a Parent/Child Class

Design classes to represent an animal, a dog, and a cat. (Perhaps to be used in a veterinary hospital or pet boarding center). Sketch out the following. (You do not need to write the code.)

What are the parent/child relationships between the classes?

What instance data variables belong in each class (list the name and type)?

What methods would go in each class (list the name, return type, and parameter list)?

Question 3: Write a Child Class

The class below describes a Shirt object. Write a class that inherits from Shirt called Sweatshirt that is also described by whether or not it is hooded. Write instance data variables, one or more constructors, getters and setters, and a toString method.

Explanation / Answer

Multiple Questions : ANswering 1st.

a..

b.Uses of super keyword

c..

If a class inherits a method from its super class, then there is a chance to override the method provided that it is not marked final.

The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides. An overriding method can also return a subtype of the type returned by the overridden method. This subtype is called a covariant return type.

When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote