WorksheetsITC C209 Final Term Quiz 1
Total questions: 75
Worksheet time: 25mins
Which statement best reflects the concept of inheritance introduced in this section?
Specialized objects are unrelated to general objects.
Specialized objects are versions of more general objects found in the real world.
General objects are always more complex than specialized objects.
Inheritance only applies to physical size differences.
Which option correctly pairs a specialized object with its more general object according to the concept of inheritance?
Bee → Animal
Grasshopper → Insect
Dalmatian → Mammal
Chihuahua → Reptile
Consider the labeled grasshopper diagram. Which reasoning best explains how inheritance helps organize its features?
Inheritance lists every body part of any organism.
Inheritance lets the grasshopper inherit common insect traits (head, thorax, abdomen, wings) while adding its own specifics.
Inheritance removes differences between insects.
Inheritance applies only to mammals, not insects.
Which statement best defines the "Is a" relationship in inheritance?
A relationship where two objects share no characteristics
A relationship indicating one object is a specialized version of another
A relationship where objects are unrelated but interact
A relationship that only applies to methods, not classes
Select the example that illustrates an "Is a" relationship.
A car has wheels
A Great Dane is a dog
A flower needs sunlight
An insect eats plants
In an "Is a" relationship, what does the specialized object inherit from the general object?
Only its name
All characteristics of the general object
None of its characteristics
Only private data fields
Which statement correctly applies the concept to Java?
Inheritance in Java creates a "has a" relationship among classes
Inheritance in Java is used only for code duplication
Inheritance in Java can create an "is a" relationship among classes
Inheritance in Java cannot extend class capabilities
In Java, why might you create a subclass that extends a class?
To remove all methods from the superclass
To create an unrelated class
To build a specialized version of the class with extended capabilities
To convert the class into an interface
In Java, extending a class primarily serves to:
Reduce its visibility to private
Create a specialized class that inherits and possibly adds features
Delete inherited methods
Prevent polymorphism
In Java, which keyword is used in the class header to indicate that one class is a subclass of another?
implements
extends
inherits
super
Given the statement: public class FinalExam extends GradedActivity, what is the relationship between FinalExam and GradedActivity?
FinalExam is a superclass of GradedActivity
FinalExam and GradedActivity are unrelated
FinalExam is a subclass of GradedActivity
GradedActivity is a subclass of FinalExam
A constructor for FinalExam is shown as public FinalExam(int questions, int missed). What is the most likely purpose of this constructor based on the class fields?
To initialize score in GradedActivity
To set numQuestions and numMissed, and compute pointsEach
To set pointsEach only
To create an empty FinalExam with default values
Strategic reasoning: If FinalExam extends GradedActivity, how can FinalExam compute and store the overall score for the exam so that getGrade() from GradedActivity works? Choose the best approach based on the provided members.
Override getGrade() in FinalExam and ignore GradedActivity
Call setScore(double) from FinalExam after computing the score so GradedActivity's getGrade() can use it
Make score public and set it directly in FinalExam
Use getNumMissed() to replace score
Which statement best describes private members of a superclass in relation to a subclass?
They are inherited and directly accessible in the subclass.
They are not inherited but still exist in memory when a subclass object is created.
They are inherited but only accessible through protected methods.
They are removed when a subclass object is created.
In an object-oriented system, how can a subclass access a private member of its superclass?
By declaring the member as private again in the subclass.
By using public methods of the superclass that expose the private member.
By referencing the member directly with super.privateMember.
It cannot be accessed in any way.
Which statement is true about public members of a superclass?
They are not inherited by the subclass.
They are inherited but cannot be accessed directly.
They are inherited and may be directly accessed from the subclass.
They exist only when the superclass object is created, not the subclass.
A subclass object is created. What happens to the superclass's private members according to the rules provided?
They do not exist in memory for the subclass object.
They exist in memory but are not inherited and require public methods for access.
They are promoted to public members in the subclass.
They become protected members automatically.
In the UML diagram, which class is the superclass that provides shared attributes and methods to graded activities?
FinalExam
GradedActivity
ScoreManager
ExamGrader
A FinalExam object needs to expose how many questions were missed and the points per question. Which pair of methods from the UML diagram should be used?
getScore() and getGrade()
setScore(s) and FinalExam()
getPointsEach() and getNumMissed()
getPointsEach() and getScore()
Which statement best describes constructor behavior in inheritance?
Constructors are inherited by subclasses.
Constructors are not inherited.
Only parameterized constructors are inherited.
Constructors are inherited only if marked public.
When a subclass object is created, which constructor executes first by default if available?
Subclass constructor
Superclass default (no-arg) constructor
Any parameterized constructor in subclass
The most recently defined constructor
What does the super keyword refer to in object-oriented programming?
An object’s interface
An object’s superclass
An object’s package
An object’s subclass
How can a subclass explicitly invoke its superclass constructor?
By calling this()
By using the extends keyword
By using the super keyword
By importing the superclass
If the superclass defines only a parameterized constructor and no default constructor, what must subclasses do?
Provide no constructors and rely on inheritance
Provide a constructor and call a superclass constructor
Use this() to skip superclass initialization
Declare the subclass as abstract to avoid constructors
Which statement about calling a superclass constructor in a subclass is correct?
It can appear anywhere in the subclass constructor.
It must be the last Java statement in the subclass constructor.
It must be the first Java statement in the subclass constructor.
It is optional when a default constructor exists in the superclass.
In the presence of a parameterized constructor in the superclass, which additional option allows subclasses to avoid explicitly calling super(...)?
Superclass provides a no-arg constructor
Subclass provides a static method
Subclass marks its constructor private
Superclass is declared final
What is the primary purpose of using super(...) within a subclass constructor?
To call another constructor in the same class
To initialize subclass fields
To initialize the superclass part of the object
To import methods from the superclass
Choose the correct execution order when both superclass and subclass define constructors and the subclass calls super(...).
Subclass constructor body executes, then superclass constructor.
Superclass constructor executes first, then subclass constructor body.
Order is undefined and depends on the JVM.
Both execute simultaneously.
Which keyword directly references the current object’s superclass in Java?
this
super
extends
implements
A subclass has no constructor defined. The superclass has a public no-arg constructor. What happens on instantiation of the subclass?
Compilation error due to missing subclass constructor
Superclass constructor is automatically called first
No constructors are called
Subclass constructor is synthesized and runs before the superclass
Which rule applies when designing subclass constructors if the superclass provides only parameterized constructors?
Subclasses may omit constructors; the compiler will add a default that calls super()
Subclasses must define a constructor and call a superclass constructor using super(...)
Subclasses must define a default constructor only
Subclasses cannot be instantiated
Which constructor executes first in a class inheritance hierarchy when creating a subclass object?
The subclass constructor
The superclass constructor
The most recently defined constructor
The constructor with the most parameters
In Java, where are you allowed to write a super statement that calls a superclass constructor?
In any method of the subclass
Only in the subclass’s constructor
In the superclass’s methods
In static initialization blocks
If a super statement appears in a subclass constructor, what is its required position?
It can be anywhere after variable declarations
It must be the last statement
It must be the first statement
It must follow a call to this()
What happens if a subclass constructor does not explicitly call a superclass constructor in Java?
Compilation fails immediately
Java automatically calls super() before the subclass constructor code executes
The subclass constructor runs without any superclass constructor
A runtime exception is thrown
A superclass lacks both a default constructor and a no-arg constructor. What must a subclass that inherits from it do?
Nothing; Java inserts a default constructor for the superclass
Declare a no-arg constructor in the subclass
Explicitly call one of the existing constructors that the superclass does have
Use this() to avoid calling the superclass
Which statement best describes the rule about calling a superclass constructor from methods other than the subclass constructor?
It is allowed using super anywhere
It is allowed only in static methods
It is not allowed; the superclass constructor cannot be called from any other method
It is allowed if the method is private
Consider a subclass constructor that begins with some logging statements and then calls super(). Which outcome aligns with Java’s constructor rules?
Compiles and runs; order of statements is flexible
Compiles but throws an exception at runtime
Fails to compile because super() must be the first statement
Runs but ignores the logging statements
In object-oriented programming, what is the term for a subclass providing its own version of a superclass method with the same signature?
Method overloading
Method overriding
Method hiding
Method binding
Which statement best explains why a subclass might override a superclass method?
To ensure the superclass method is always called first
Because the subclass is more specialized and may need a more suitable method
To change the method name for readability
To avoid using inheritance
When overriding, what must match between the subclass method and the superclass method?
Method name only
Return type only
Method signature
Access modifier only
What happens when an object of the subclass invokes an overridden method?
The superclass’s version is executed
Both versions execute sequentially
The subclass’s version is executed
A runtime error occurs
Which phrase from the material defines method overriding?
A subclass defines additional methods
A subclass may have a method with the same signature as a superclass method
A superclass calls a subclass method
A subclass duplicates a field
Select the true statement about overriding from the material.
Overriding requires changing the parameter list
Overriding is possible only if the subclass removes the method from the superclass
Overriding uses the same signature as the superclass method
Overriding always changes the return type
Why might a subclass replace an inadequate superclass method?
To eliminate polymorphism
To provide a more suitable implementation for the specialized subclass
To prevent objects from invoking methods
To force compilation-time binding
According to the material, which version of an overridden method does a subclass object use?
Superclass’s version
Subclass’s version
Either version randomly
A default library version
Which pair correctly matches method name and return type shown for GradedActivity?
getGrade(): double
getScore(): char
setScore(double): void
CurvedActivity(percent: double): void
In the CurvedActivity class, which member listed is a constructor?
getRawScore(): double
getPercentage(): double
setScore(s: double): void
CurvedActivity(percent: double)
Which keyword allows a subclass method to call the overridden superclass method?
this
super
extends
parent
Which statement correctly distinguishes overloading from overriding?
Overloading requires the same signature; overriding requires different signatures
Overloading uses different signatures for methods with the same name; overriding uses the same signature
Overloading happens only across classes; overriding happens only within a class
Overloading and overriding are identical concepts
When a method overrides another method, how do their signatures compare?
They must be different
They must be the same
They can be either the same or different
They must be private
Which scenario is valid for method overriding based on the material?
Between unrelated classes without inheritance
Only within an inheritance relationship
Within a single class with no inheritance
Across packages regardless of class relationships
Which statement about overloading and overriding in inheritance relationships is accurate?
Only overloading can occur in an inheritance relationship
Neither overloading nor overriding can occur in inheritance
Both overloading and overriding can take place in an inheritance relationship
Overloading requires inheritance while overriding does not
Choose the best description of method overloading.
A subclass provides a new implementation with the same signature as a superclass method
Multiple methods share the same name but have different signatures
A method hides a variable from a superclass
A method is called using the super keyword
In Java, which access specifier allows access to class members from subclasses and from classes in the same package?
private
public
protected
default (package-private)
Protected access for a member is best described as being _______.
more restrictive than private
less restrictive than public but more than private
identical to default (package) access
accessible only outside the package
Which statement about protected members is TRUE?
They cannot be accessed by subclasses.
They can be accessed by any class, regardless of package.
They can be accessed by subclasses and by classes in the same package.
They are only accessible within the defining class.
Using protected instead of private makes some tasks easier because _______.
it blocks access from subclasses
subclasses and same-package classes have unrestricted access
it automatically generates public getters
it prevents package access
According to the guidance, what is generally recommended for fields?
Declare fields as protected to simplify inheritance.
Declare fields as public for maximum accessibility.
Make all fields private and provide public methods to access them.
Use default access for fields to avoid verbosity.
If no access specifier is provided for a class member in Java, what access level is applied by default?
private
public
protected
package access (default)
Which statement correctly explains package access in the context of protected members?
Only subclasses in different packages can access the member.
Any method in the same package may access the member.
Only the defining class can access the member.
Access is restricted to public methods only.
Which access modifier allows a member to be accessed by subclasses and all other classes inside the same package, but not by classes outside the package (except subclasses)?
default (no modifier)
public
protected
private
Which access modifier makes a member accessible to all classes everywhere (both inside and outside the package)?
public
protected
default (no modifier)
private
A class member should be hidden from all other classes, including subclasses, regardless of package. Which modifier fits this requirement?
protected
default (no modifier)
public
private
Which statement best describes default (no modifier) access?
Accessible to subclasses outside the package only
Accessible to all classes inside the same package but not outside the package
Accessible to all classes everywhere
Not accessible to any class
You have a subclass in a different package that needs to access a superclass member. Which single modifier enables this access while still restricting access from non-subclass classes outside the package?
default (no modifier)
public
protected
private
Which statement best defines a class hierarchy in Java?
A graphical depiction of how variables are stored in memory
A diagram showing inheritance relationships between classes
A list of all methods available in a class
A runtime stack trace of method calls
In the illustrated hierarchy, which class is the direct superclass of PassFailExam?
Object
GradedActivity
PassFailActivity
FinalExam
What is the role of the Object class in Java?
It is the root class from which all Java classes are directly or indirectly derived
It only provides support for graphical user interfaces
It is a utility class used for mathematical operations
It is a package that contains primitive types
If a class does not specify the extends keyword, from which class is it automatically derived?
String
System
Object
Runtime
Consider the snippet: "public class MyClass { /* no extends */ }". What is true about MyClass?
It is not a valid Java class
It automatically extends Object
It extends String by default
It cannot use methods from java.lang
Which method is used to compare two objects for logical equality?
compareTo()
equals()
toString()
notify()
In the chain shown for PassFailExam, what is the correct top-to-bottom order of classes?
PassFailExam → PassFailActivity → GradedActivity → Object
Object → GradedActivity → PassFailActivity → PassFailExam
Object → PassFailActivity → GradedActivity → PassFailExam
GradedActivity → Object → PassFailActivity → PassFailExam
Which statement accurately describes inheritance as shown in the diagrams?
Subclasses inherit from their parents, forming chains that lead back to Object
Each class in Java must inherit from exactly two superclasses
Inheritance only applies to methods, not fields
FinalExam inherits from PassFailExam in the diagram
Which conclusion can be drawn about PassFailExam from the chain of inheritance shown?
It cannot use any methods from Object
It inherits members from Object through its superclasses
It directly extends Object
It is unrelated to GradedActivity
