Needing help with this assignment! 3.1 Is it required to provide an accessor and
ID: 3665019 • Letter: N
Question
Needing help with this assignment!
3.1 Is it required to provide an accessor and/or mutator method for every instance variable of a class? If yes, explain
why this is required, and if no, explain why not.
3.2 Suppose the class Sub extends Sandwich. Which of the following statements are legal?
Sandwich x = new Sandwich();
Sub y = new Sub();
(a) x = y;
(b) y = x;
(c) Sub y = new Sandwich();
(d) Sandwich x = new Sub();
3.3 True or False? A subclass declaration will generally contain declarations for instance variables that are specific to
object of that subclass, i.e., those instance variables represent attributes that are not part of superclass objects.
3.4 True or False? A superclass declaration will generally contain declarations for instance variables that are specific to
objects of that superclass, i.e., those instance variables represent attributes that are not part of subclass objects.
3.6 Explain what an overloaded method is and give an example.
3.7 Explain what an overridden method is and give an example.
3.8 Explain what accidental overloading is and the preferred Java method for preventing it.
3.9 If an overridden method in a subclass needs to call the overridden superclass method, how is this accomplished?
3.10 True or False? It is legal for a method in a class to overload another method also in the same class. Explain.
3.11 True or False? It is legal in a class for a method to override another method also in the same class. Explain.
3.12 True or False? It is legal in a subclass for a method to overload a method in the superclass. Explain.
3.13 True or False? It is legal in a subclass for a method to override a method in the superclass. Explain.
3.14 True or False? It is legal in a superclass for a method to overload a method in a subclass. Explain.
3.15 True or False? It is legal in a superclass for a method to override a method in a subclass. Explain.
3.16 In a subclass constructor, the superclass default constructor is called automatically before the statements of the
subclass constructor begin executing. Suppose we wish to call a different superclass constructor (i.e., not the default
constructor) from the subclass constructor. Explain how this is accomplished and give an example.
3.17 Explain how an abstract class differs from a concrete class.
4 Objects, Classes, Polymorphism, and Interfaces
4.1 In the video lecture for Interfaces : Section 6 we discussed an example program that implements an inheritance
hierarchy (Mammal is the superclass of Cat and Dog; Insect is the superclass ofCricket). Which method or methods
in that program are called polymorphically?
4.2 Write the Java code to declare a new class Bee which is a subclass of Insect. The noise made by a Bee is "Buzz".
4.3 Write the Java code to declare a new abstract class Amphibian that implements the MakesNoise interface.
4.4 Write the Java code to declare a new class Frog which is a subclass ofAmphibian. The noise made by a Frog is
"Ribbet".
4.5 Modify the run() method of Main and add some Bees and Frogs to critters. Build your program and verify that it
works correctly. Include all of your .java source code files in the zip archive that you submit for grading.
5 GUI Programming
5.1 For these exercises, include your completed .java files in the zip archive that you submit for grading. Complete the
code in the provided View class to implement this GUI interface for a calculator. The calculator does not have to be
fully functional; the primary objective of the assignment is to implement the GUI.
5.2 Complete the code in actionPerformed() so when the Exit button is clicked, the application will terminate.
5.3 Complete the code in actionPerformed() so when the About button is clicked, the application will display this about
Explanation / Answer
3.1
It is not necessary. But we have to provide accessor and mutator method for every private instance variable if we want to use the variable outside the class.
3.2
(a) and (c) are legal
as sub is a sandwich, so, a sandwich instance can be set to a sub.
3.3
True.
3.4
False. A subclass can access all the variables of a superclass, unless they are private.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.