Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Object Roles and the Importance of Polymorphism


Activity 3

Look at the diagram below and, noting that Student is an abstract class, decide which of the following code segments are
valid....

Note FtStudent is short for Full Time Student and PtStudent is short for Part Time Student.

a) Student s = new Student();
Lecturer l = new Lecturer();
l.Help(s);

b) Student s = new FtStudent();
Lecturer l = new Lecturer();
l.Help(s);

Feedback 3

a) This is not valid as class Student is abstract and cannot be instantiated
b) This is valid. FtStudent is a type of Student and can be assigned to variable of type Student. This can
then be passed as a parameter to l.Help()
Free download pdf