Java Programming Assignment on Inheritance and Polymorphism Concepts
VerifiedAdded on 2023/04/23
|4
|710
|381
Homework Assignment
AI Summary
This Java programming assignment solution covers key concepts from Chapters 9 and 10, focusing on inheritance and polymorphism. The solution explains the use of the `super` keyword for calling parent class methods, the `@Override` declaration for method overriding, and the role of constructors...

Running head: JAVA PROGRAMMING
Java Programming
Name of the Student
Name of the University
Java Programming
Name of the Student
Name of the University
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

2
JAVA PROGRAMMING
Chapter 9
9.9 a) As commented by Potts & Friedel (2018), the method earnings () has been overridden in
a sub class. The statement calls its parent class earnings method from the sub class that is inherits
methods from parent class.
o super.earnings()
In this case, super is a keyword which, is utilized for calling parent class method earnings ().
b) @Override declaration -Description
The declaration @Override method has been helping in indicating method is override method of
its super class method. The super class @Override method signature and child class @Override
method signature are equal. Method definitions of super class and child class may or may not be
same.
c) It is used to call the constructor of the parent class by passing the two mentioned arguments.
The parent class constructor will accept this arguments and initialize the object attributes
accordingly.
Chapter 10
10.6 Polymorphism has been allowing creation of new subclasses for extending behavior. In
the absence of polymorphism, conditional code needs to be written for testing new behavior
being implemented. The new class has been becoming part of the classification. Polymorphism
helps in using same functions with different class type. This concept refers to overriding
JAVA PROGRAMMING
Chapter 9
9.9 a) As commented by Potts & Friedel (2018), the method earnings () has been overridden in
a sub class. The statement calls its parent class earnings method from the sub class that is inherits
methods from parent class.
o super.earnings()
In this case, super is a keyword which, is utilized for calling parent class method earnings ().
b) @Override declaration -Description
The declaration @Override method has been helping in indicating method is override method of
its super class method. The super class @Override method signature and child class @Override
method signature are equal. Method definitions of super class and child class may or may not be
same.
c) It is used to call the constructor of the parent class by passing the two mentioned arguments.
The parent class constructor will accept this arguments and initialize the object attributes
accordingly.
Chapter 10
10.6 Polymorphism has been allowing creation of new subclasses for extending behavior. In
the absence of polymorphism, conditional code needs to be written for testing new behavior
being implemented. The new class has been becoming part of the classification. Polymorphism
helps in using same functions with different class type. This concept refers to overriding

3
JAVA PROGRAMMING
(Gavrilović et al., 2018). Overriding methods helps in allowing a subclass for overriding a
functionality provided in the super class.
10.7 There are various ways by which subclass and superclass references can be assigned to
variables of subclass and superclass types as mentioned below:
1. Assigning a superclass reference to a super class variable
2. Assigning a subclass reference to a subclass variable
3. Assigning a subclass object’s reference to a superclass
This reference need to be utilized in the superclass members. However, this code tends to
subclass only members with help of superclass variable. Attempting for assigning a superclass
object’s reference to a subclass variable has been providing compilation error (Sebesta, 2016).
Therefore, for avoiding this error, the superclass reference needs to be downcast to a subclass
type. Therefore, at execution time, the object needs to be refers to not a subclass object. The
instanceof operator has been used for ensuring has been performed if the object is a subclass
object.
10.8 An abstract refers to general notion that means to be an object of same class. Abstract
classes contain data and methods that can be declared abstract as the methods are not able to use
in other cases. Therefore, objects of an abstract class cannot be instantiated. Subclasses needs to
be declared for implementation of abstract methods which, has been appropriate for each specific
methods (Carpenter et al., 2017). Classes that are related to the interface whereas concrete
subclass of the same abstract. Interface references has been used for evoking polymorphic
behavior of an abstract superclass references. Interface has only abstract methods and supports
JAVA PROGRAMMING
(Gavrilović et al., 2018). Overriding methods helps in allowing a subclass for overriding a
functionality provided in the super class.
10.7 There are various ways by which subclass and superclass references can be assigned to
variables of subclass and superclass types as mentioned below:
1. Assigning a superclass reference to a super class variable
2. Assigning a subclass reference to a subclass variable
3. Assigning a subclass object’s reference to a superclass
This reference need to be utilized in the superclass members. However, this code tends to
subclass only members with help of superclass variable. Attempting for assigning a superclass
object’s reference to a subclass variable has been providing compilation error (Sebesta, 2016).
Therefore, for avoiding this error, the superclass reference needs to be downcast to a subclass
type. Therefore, at execution time, the object needs to be refers to not a subclass object. The
instanceof operator has been used for ensuring has been performed if the object is a subclass
object.
10.8 An abstract refers to general notion that means to be an object of same class. Abstract
classes contain data and methods that can be declared abstract as the methods are not able to use
in other cases. Therefore, objects of an abstract class cannot be instantiated. Subclasses needs to
be declared for implementation of abstract methods which, has been appropriate for each specific
methods (Carpenter et al., 2017). Classes that are related to the interface whereas concrete
subclass of the same abstract. Interface references has been used for evoking polymorphic
behavior of an abstract superclass references. Interface has only abstract methods and supports
You're viewing a preview
Unlock full access by subscribing today!

4
JAVA PROGRAMMING
multiple inheritance. An interface has been implemented by the help of keyword named as
implement.
References
Carpenter, B., Gelman, A., Hoffman, M. D., Lee, D., Goodrich, B., Betancourt, M., ... & Riddell,
A. (2017). Stan: A probabilistic programming language. Journal of statistical
software, 76(1).
Gavrilović, N., Arsić, A., Domazet, D., & Mishra, A. (2018). Algorithm for adaptive learning
process and improving learners’ skills in Java programming language. Computer
Applications in Engineering Education, 26(5), 1362-1382.
Potts, A., & Friedel, D. H. (2018). Java programming language handbook. Coriolis Group
Books.
Sebesta, R. W. (2016). Concepts of programming languages.
JAVA PROGRAMMING
multiple inheritance. An interface has been implemented by the help of keyword named as
implement.
References
Carpenter, B., Gelman, A., Hoffman, M. D., Lee, D., Goodrich, B., Betancourt, M., ... & Riddell,
A. (2017). Stan: A probabilistic programming language. Journal of statistical
software, 76(1).
Gavrilović, N., Arsić, A., Domazet, D., & Mishra, A. (2018). Algorithm for adaptive learning
process and improving learners’ skills in Java programming language. Computer
Applications in Engineering Education, 26(5), 1362-1382.
Potts, A., & Friedel, D. H. (2018). Java programming language handbook. Coriolis Group
Books.
Sebesta, R. W. (2016). Concepts of programming languages.
1 out of 4
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.