Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the 'Is-a' relationship represent in programming?
It represents inheritance where one class is a specialized version of another class. For example, a Dog 'is-a' Animal.
Click to reveal answer
beginner
In C#, which symbol is used to express an 'Is-a' relationship?
The <code>:</code> symbol is used after the class name to inherit from a base class, showing an 'Is-a' relationship.
Click to reveal answer
beginner
Example: If class Car inherits from class Vehicle, what kind of relationship is this?
This is an 'Is-a' relationship because a Car is a type of Vehicle.
Click to reveal answer
intermediate
Why is the 'Is-a' relationship important in object-oriented programming?
It helps reuse code and organize classes logically by showing that one class shares properties and behaviors of another.
Click to reveal answer
intermediate
Can an 'Is-a' relationship exist between unrelated classes?
No. 'Is-a' means one class inherits from another or implements an interface, showing a clear hierarchy or contract.
Click to reveal answer
Which symbol in C# shows an 'Is-a' relationship?
A:
Bnew
Cthis
Dvar
✗ Incorrect
The ':' symbol is used in C# to inherit from a base class, expressing an 'Is-a' relationship.
If class Bird inherits from Animal, what does this mean?
AAnimal is a type of Bird
BBird is a type of Animal
CBird has an Animal
DBird and Animal are unrelated
✗ Incorrect
Inheritance means Bird 'is-a' Animal, so Bird is a specialized form of Animal.
Which of these is NOT an example of an 'Is-a' relationship?
ADog inherits from Animal
BCar inherits from Vehicle
CHouse has a Door
DStudent inherits from Person
✗ Incorrect
'Has-a' relationship means one class contains another, not 'Is-a'.
What does the 'Is-a' relationship help with in programming?
AChanging variable types
BCreating unrelated classes
CRunning programs faster
DCode reuse and logical class organization
✗ Incorrect
'Is-a' relationships help reuse code and organize classes logically.
Which statement is true about 'Is-a' relationships?
AThey show inheritance or interface implementation
BThey show one class contains another
CThey are used for variable declaration
DThey are unrelated to object-oriented programming
✗ Incorrect
'Is-a' relationships show inheritance or interface implementation in OOP.
Explain the 'Is-a' relationship in your own words and give a simple example in C#.
Think about how one class can be a specialized version of another.
You got /4 concepts.
Why is understanding the 'Is-a' relationship important when designing classes in object-oriented programming?
Consider how it helps avoid repeating code and keeps your program organized.
You got /4 concepts.
Practice
(1/5)
1. What does the Is-a relationship represent in C# programming?
easy
A. A class contains another class as a member
B. A class inherits properties and methods from another class
C. A class is converted into another class
D. A class is unrelated to any other class
Solution
Step 1: Understand inheritance concept
The Is-a relationship means one class inherits from another, gaining its features.
Step 2: Identify correct description
A class inherits properties and methods from another class correctly describes inheritance, while others describe different concepts.
Final Answer:
A class inherits properties and methods from another class -> Option B
Quick Check:
Is-a means inheritance = B [OK]
Hint: Is-a means inheritance, not containment or conversion [OK]
Common Mistakes:
Confusing Is-a with Has-a (containment)
Thinking Is-a means type conversion
Assuming unrelated classes have Is-a relationship
2. Which of the following is the correct syntax to express an Is-a relationship in C#?
easy
A. class Dog inherits Animal {}
B. class Dog extends Animal {}
C. class Dog : Animal {}
D. class Dog -> Animal {}
Solution
Step 1: Recall C# inheritance syntax
In C#, the colon (:) symbol is used to indicate inheritance.
Step 2: Compare options
class Dog : Animal {} uses the correct syntax 'class Dog : Animal {}'. Others use incorrect keywords or symbols.
Final Answer:
class Dog : Animal {} -> Option C
Quick Check:
C# inheritance uses ':' = C [OK]
Hint: Use ':' to inherit in C# classes [OK]
Common Mistakes:
Using 'inherits' keyword (not valid in C#)
Using 'extends' (Java syntax)
Using arrows or other symbols
3. Consider this code:
class Animal { public string Speak() => "Sound"; } class Dog : Animal { }
What is the output of:
var d = new Dog(); Console.WriteLine(d.Speak());
medium
A. Runtime error
B. Dog
C. Compile error
D. Sound
Solution
Step 1: Understand inheritance effect
Dog inherits from Animal, so Dog has the Speak() method.
Step 2: Predict method call output
Calling d.Speak() returns "Sound" from Animal class.
Final Answer:
Sound -> Option D
Quick Check:
Inherited method returns "Sound" = A [OK]
Hint: Inherited methods can be called on child objects [OK]
Common Mistakes:
Expecting Dog to override Speak() automatically
Thinking code causes compile or runtime error
Confusing output with class name
4. Identify the error in this code snippet:
class Animal { } class Dog Animal { }
medium
A. Missing colon ':' between Dog and Animal
B. Dog cannot inherit from Animal
C. Animal class must be abstract
D. Dog class must have a constructor
Solution
Step 1: Check inheritance syntax
In C#, inheritance requires a colon ':' between child and parent class names.
Step 2: Identify missing symbol
The code misses ':' between Dog and Animal, causing syntax error.
Final Answer:
Missing colon ':' between Dog and Animal -> Option A
Quick Check:
Inheritance needs ':' = A [OK]
Hint: Always use ':' to inherit in C# [OK]
Common Mistakes:
Forgetting the colon ':'
Thinking parent class must be abstract
Assuming constructor is mandatory
5. Given these classes:
class Vehicle { public virtual string Move() => "Moving"; } class Car : Vehicle { public override string Move() => "Car is moving"; } class Bike : Vehicle { }
What will be the output of:
Vehicle v1 = new Car(); Vehicle v2 = new Bike(); Console.WriteLine(v1.Move()); Console.WriteLine(v2.Move());
hard
A. Car is moving\nMoving
B. Moving\nMoving
C. Car is moving\nBike is moving
D. Compile error due to missing override
Solution
Step 1: Understand virtual and override behavior
Car overrides Move(), so v1.Move() calls Car's version. Bike does not override, so v2.Move() calls Vehicle's version.
Step 2: Predict output lines
v1.Move() outputs "Car is moving"; v2.Move() outputs "Moving".
Final Answer:
Car is moving\nMoving -> Option A
Quick Check:
Override changes output, no override uses base = D [OK]
Hint: Override changes method output; no override uses base method [OK]