0% found this document useful (0 votes)
92 views

Module 5 Class Activity

This document contains questions and answers about object-oriented programming concepts in C#. 1. Inheritance allows a derived class to inherit attributes and behaviors from a base class. A constructor is a special type of method that is called when an object is created to initialize it. 2. The main objectives of inheritance are to reduce development time, standardize functionality, and save developers' energy. There are three types of errors: syntax errors from incorrect code, run-time errors appearing during execution, and logic errors from assigning values to the wrong variables. 3. Method overriding allows functions with the same signatures to be invoked using a base class reference, even if they belong to different classes in an inheritance hierarchy.

Uploaded by

Nadia Noack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Module 5 Class Activity

This document contains questions and answers about object-oriented programming concepts in C#. 1. Inheritance allows a derived class to inherit attributes and behaviors from a base class. A constructor is a special type of method that is called when an object is created to initialize it. 2. The main objectives of inheritance are to reduce development time, standardize functionality, and save developers' energy. There are three types of errors: syntax errors from incorrect code, run-time errors appearing during execution, and logic errors from assigning values to the wrong variables. 3. Method overriding allows functions with the same signatures to be invoked using a base class reference, even if they belong to different classes in an inheritance hierarchy.

Uploaded by

Nadia Noack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

06 April 2020

Class Activity

Module 5

Question One (20 Marks)

1. Define the term Inheritance and give one example of class. (4 Marks)

 A derived class that inherits attributes and behaviors from a based class.

Public ParentCat {

Public Kitten: ParentCat {

2. Differentiate between Based and Derived. (4 Marks)

The Based class is the Parent class (main class) and the Derived class is the child class
(subclass). The derived class inherits attributes and behaviors from a based class.

3. Identify four access modifiers. (4 Marks)


 Public
 Internal
 Private
 Protected

4. What is a constructor? (3 Marks)

Constructor is a block of code similar to a method that’s called when an instance of an


object is created. Constructor also contains the collection of instructions that are executed
at the time of Object creation

5. Differentiate between Sealed and Abstract Class (4 Marks)

A sealed class is a class that cannot be inherited. Sealed keyword, which


enables this class to seal all its variables, methods and properties.

An abstract class enables other classes to inherit from this class, but
forbids to instantiate. One can inherit from an abstract class but we
cannot create objects of an abstract class.
6. What is overloading? (1 Marks)

Method Overloading in C# is when you have two or more methods with the same name but
different signatures.

Question Two (10 Marks)

1. What are main objectives of Inheritance? (2 Marks)


 Reduce development time
 Standardize functionality
 Saving developers energy

2. List and Explain the three types of errors (6 Marks)

Syntax Errors:

Most Syntax errors are caused by mistakes that you make when writing code. Programming
language differ from the other programming languages so you can’t use the save syntax,
example you can’t use python format in java.

Run-time Errors:

Run-time errors are those that appear only after you compile and run your code.

Logic Errors:

A logic error (or logical error) is a mistake in a program's source code that results in
incorrect or unexpected behavior. For example, assigning a value to the wrong variable may
cause a series of unexpected program errors.

3. What is overriding? (2 Marks)

Method overriding is a feature that allows you to invoke functions (that have the same
signatures) that belong to different classes in the same hierarchy of inheritance using the base
class reference.

Grand Total 30 Marks

You might also like