Save
SEMESTER 01
PLATFORM DEV THEORY
Chapter 9 Object Orientation: classes based inheritance
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Soeroe
Visit profile
Cards (49)
What is class-based inheritance in object-oriented programming?
It is a feature that allows new
classes
to reuse, extend, and modify
behavior
defined in other classes.
View source
What is the difference between a base class and a derived class?
The base class is the class whose
members
are inherited, while the derived class is the class that inherits those members.
View source
What does it mean that inheritance is transitive?
If
ClassC
is derived from
ClassB
, and ClassB is derived from
ClassA
, then ClassC inherits members from both ClassB and ClassA.
View source
What are the alternative terms for base class and derived class?
Base class is also called the
parent class
, and derived class is called the
child class
.
View source
What happens if class B inherits from class A?
Every
instance
of class B is also an instance of class A.
View source
Why is it beneficial to have a Weapon class inherit from an Item class?
It allows the Weapon class to reuse the logic defined in the Item class, promoting
code efficiency
.
View source
What is the purpose of the base keyword in a derived class constructor?
The base keyword is used to call the constructor of the
base class
from the derived class constructor.
View source
What members are not inherited by a derived class?
Constructors
and
finalizers
are not inherited by a derived class.
View source
Can a derived class remove inherited members?
No, a derived class cannot remove inherited members or change their
access modifier
to a more restrictive one.
View source
What happens if no base class constructor is explicitly called in a derived class?
The base class constructor without arguments is called
implicitly
.
View source
What does the protected keyword do in C#?
The protected keyword makes a member accessible to the defining class and its
derived classes
.
View source
What is the purpose of the override keyword in C#?
The override keyword allows a
derived class
to replace the
base class
logic with new logic for an inherited method.
View source
What is System.Object in C#?
System.Object is the root of the type system in C#, and every class inherits directly or
indirectly
from it.
View source
What happens when a class does not explicitly specify a base class?
The class implicitly inherits from
System.Object
.
View source
Why is the ToString method important in System.Object?
It provides a
text
representation
of an
object
, which is useful in
many situations.
View source
What conditions must be met to override a method in a child class?
The parent class must define the method as
virtual
, and the child class must use the
keyword
override.
View source
What are the key concepts of class-based inheritance?
Inheritance allows for
code reuse
and specialization.
Base class
members can be inherited by
derived classes
.
Constructors are not inherited, but can be called using the base keyword.
The
protected
keyword allows access to derived classes.
The
override
keyword enables method replacement in derived classes.
View source
What are the implications of using inheritance in object-oriented programming?
Promotes code reuse and reduces
redundancy
.
Allows for
polymorphism
and dynamic method resolution.
Can lead to complex
hierarchies
if not managed properly.
May introduce tight
coupling
between classes.
View source
What are the differences between hiding and overriding methods?
Hiding: Uses the keyword
new
; does not require the base method to be
virtual
.
Overriding: Uses the keyword override; requires the base method to be virtual.
Hiding creates a new method, while overriding replaces the base method logic.
View source
What is the role of the base keyword in derived classes?
Calls the constructor of the
base class
.
Allows access to base class
methods
and
properties.
Facilitates
method overriding
by referencing the base class implementation.
View source
What are the consequences of not having a parameterless constructor in the base class?
Derived classes
cannot be instantiated without explicitly calling a base class constructor.
If no accessible parameterless constructor exists, it generates a
compiler error
.
The
default constructor
is added by the compiler only if no constructors are defined in the class.
View source
What class does Student inherit from?
Person
View source
What is the purpose of the private set in the FirstName property of the Person class?
It
restricts
the
modification
of
FirstName
to within the
class
only
View source
What does the constructor of the Person class initialize?
FirstName
and
LastName
View source
What does the ToString method in the Person class return?
LastName
,
FirstName
( Person )
View source
What is the return type of the ToText1 method in the Person class?
string
View source
How does the Student class's constructor differ from the Person class's constructor?
The Student constructor also initializes
MajorName
View source
What does the new keyword indicate in the ToString method of the Student class?
It hides the inherited ToString method from the
Person
class
View source
What happens when a Student object is accessed through a Person reference?
It uses the
ToString
implementation from the Person
class
View source
What is the consequence of not using the override keyword in the Student class's ToString method?
It
hides
the method instead of
overriding
it
View source
What does the sealed keyword do when applied to a class?
It prevents the class from being
inherited
View source
What does the abstract keyword indicate when applied to a method?
It indicates that the method has no body and must be implemented in
derived
classes
View source
Can an abstract class be instantiated directly?
No
, it
cannot
be instantiated directly
View source
What is polymorphism in the context of object-oriented programming?
It allows an object to be assigned to
references
of different types
View source
What is the purpose of the is operator in type checking?
It checks if a value can be
assigned
to a
reference
of a type
View source
What happens if a child class does not implement all abstract methods?
The child class must also be defined as
abstract
View source
How does the as operator differ from the is operator?
The as operator attempts to
cast
and returns null if it fails
View source
What is the purpose of the OfType method in LINQ?
It filters a collection to include only elements of a
specified
type
View source
What are the consequences of using composition vs inheritance in code reuse?
Both can be done right or wrong
Inheritance can lead to issues like the
Circle-ellipse problem
Composition is often preferred for flexibility
Unity scripts
inherit from
MonoBehaviour
, showing a mixed approach
View source
What is the strategy pattern in programming?
A design pattern that allows selecting an
algorithm
at runtime
Involves defining a common
interface
for different algorithms
Enables different implementations to be used interchangeably
Reduces the need for
conditional logic
in code
View source
See all 49 cards