Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 2 out of 9 pages
Exam (elaborations)

CSCI 1302 Exam 2 study guide quiz question and answers graded A+ 2025/2026

Document preview thumbnail
Preview 2 out of 9 pages

CSCI 1302 Exam 2 study guide quiz question and answers graded A+ 2025/2026

Content preview

CSCI 1302 Exam 2 study guide

What is inheritance in Java? - ANS-defining a new class by extending an existing class/creating
a new class based on definition of other classes

What is inheritance good for? - ANS-reuse and avoiding redundancy

What type of relationship is inheritance? - ANS-is-a relationship

example: If we have an animal class and a dog class. The dog class can extend the animal
class, since a dog "is a" animal.

What does the newly defined class that extends the superclass gain? - ANS-all accessible data
properties and methods, but NOT constructors

Between an Animal class and a Dog class, which is the subclass? - ANS-the dog class,
because it is the extended class

T or F? Subclass "is a" superclass - ANS-true.
for example, a cat is an animal

Other terms for superclass? - ANS-parent class, base class, supertype

Other terms for subclass? - ANS-child class, extended class, derived class, subtype

What can a subclass do? - ANS-it can add data, add methods, and override methods (from
parent class)

If changes are made to the superclass, does the subclass automatically receive these changes?
- ANS-yes

What must a subclass use? - ANS--get/set methods for superclass data members (data
members in superclass should be private)

How do you indicate inheritance in a UML diagram? - ANS-an arrow that points from the
subclass to the superclass

example: The Dog class would point to the Animal, its parent class

Define a Cat class that extends Animal class - ANS-public class Cat extends Animal {
// implement cat class
}

, How must the private data fields in parent class be accessed? - ANS-through getter and setters,
due to visibility rules

T or F? Inheritance models "is a" relationship but should not be used for every "is a"
relationship. - ANS-true, just use your best judgement based on classes and their
characteristics, not based on convenience

Can you inherit from multiple classes in java? - ANS-no, java only has single inheritance

Can a superclass have multiple subclasses? - ANS-yes. a superclass can have multiple
subclasses but a subclass can not have more than one parent class.

for example, a Dog class, Elephant class, and Cat class can all extend an Animal class

what does the super keyword do? - ANS-it is similar to the "this" keyword but it refers to the
parent class instead of self. You can use it to access a constructor or method that is in the
superclass.

example: super(); calls the default constructor from the superclass.

if calling a superclass constructor, where does the keyword need to be used? - ANS-at the
beginning or the first line, just like with the this keyword.

how come you get everything for "free" when it comes to superclass and subclasses - ANS-java
automatically calls super in child class constructors

what does java execute up to the "extends" chain? - ANS-all default superclass constructors.
this is referred to as constructor chaining

what is constructor chaining and how does it work? - ANS-The process of calling one
constructor from within another constructor. Constructor invocations chain backwards through
ALL parent classes automatically

example of calling the toString() of the superclass? - ANS-super.toString()

what is overriding a method? - ANS-language feature that allows a subclass or child class to
provide a specific implementation of a method that is already provided by the parent class.

example:
@Override
public String toString() {
//whatever string you want to return
}

Document information

Uploaded on
March 19, 2025
Number of pages
9
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$12.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
1
Followers
0
Items
638
Last sold
1 year ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions