Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
28 views

Module 4 Class Activity

This document contains a class activity with three questions about object-oriented programming concepts in C#. Question One defines class and provides an example. It differentiates between value and reference types and identifies access modifiers. Question Two discusses interfaces, implementing multiple interfaces, and the difference between implicit and explicit implementation. Question Three defines generics, lists advantages of generics, ways to use generics, and differentiates between Stack and LinkedList. The overall objective is to assess knowledge of key OOP concepts in C# like classes, interfaces, generics and others.

Uploaded by

Nadia Noack
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Module 4 Class Activity

This document contains a class activity with three questions about object-oriented programming concepts in C#. Question One defines class and provides an example. It differentiates between value and reference types and identifies access modifiers. Question Two discusses interfaces, implementing multiple interfaces, and the difference between implicit and explicit implementation. Question Three defines generics, lists advantages of generics, ways to use generics, and differentiates between Stack and LinkedList. The overall objective is to assess knowledge of key OOP concepts in C# like classes, interfaces, generics and others.

Uploaded by

Nadia Noack
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

01 April 2020

Class Activity

Module 4

Question One (20 Marks)

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

A class is a user-defined blueprint/abstract or prototype from which objects are created.

An example of a class is a dog because it has legs, tail, head, etc.

2. Differentiate between value and reference type. (4 Marks)

Value Type:

Contain data directly

Int Nadia = 5;

Reference Type:

Point to an object in memory

Object Nadia = new object();

3. Identify three access modifiers. (3 Marks)


 Public
 Internal
 Private

4. What is a constructor? (3 Marks)

A constructor is a piece of a variable or a type of method.

You can use constructors to initialize member variables.

5. Differentiate between Static and Non-Static Class (4 Marks)

Static class call members directly on the class name.

Non-static classes can be instantiated.

6. What is casting in C#? (2 Marks)

Typecasting is when you assign a value of one data type to another type.
Question Two (14 Marks)

1. What is the main objective of Interface? (2 Marks)

Interfaces are a set of characteristics and behaviors.

2. Write the syntax code of creating the interface (4 Marks)

Public interface INadia

Int Compare (Object A, Object B);

3. Write a declaration that implementing multiple interface (2 Marks)

Public class Person : INadia, INatacha

Int Name = “”;

Int Talk = “”;

4. Differentiate between implicit and explicit implementation (4 Marks)

Implicit implementation: implement every member of every interface.

Explicit implementation: if two interfaces have a member with the same name.

5. What is the function of Arraylist.Sort method? (2 Marks)

The Arraylist.Sort method calls members to sort items in a collection.

Question Three (16 Marks)

1. Define the term Generic (2 Marks)

Generic allows you to define a class with placeholders for the type of its fields, methods,
parameters, etc.

2. Identify three advantages of Generic (3 Marks)


 Type safety
 No casting
 No boxing and unboxing

3. Identify six way of using Generic (6 Marks)

 where E: <name of interface>


 where E: <name of base class>
 where E: U
 where E: new()
 where E: struct
 where E: class

4. Differentiate between Stack<T> and LinkedList <T> (4 Marks)

Stack<T> is a last-in, first-out the collection.

LinkedList<T> is a generic list in which each item is linked to the previous item and the next
item in the collection.

5. What is the main objective of Generic (1 Mark)

Generic help uses with type safety so that we can’t make any errors in the compile time.

Grand Total 50 Marks

You might also like