OOP
UML
Casting
Abstract
100

Check the UML class diagram.

Write the code for the child class.

PingPong(string name) : base(name)

{ ..}

100

In a  UML Class Diagram,  the (+) plus sign indicates:

public

100

class Card { ... }
class Birthday :  Card { ... }
class Holiday : Card { ... }
class NewYear : Holiday { ... }
//Will the following statement(s) compile and if yes what type of casting is applied?
Card card = new Birthday() ;
Holiday hd= card as Holiday;

Yes, it will compile

hd will be null

100

Can an abstract class define both abstract methods and non-abstract methods?

Yes.

200

What does a constructor of a class return?

Returns a reference to the object that is created in the memory (HEAP). 

However, constructors do not have a return statement.

200

In a  UML Class Diagram,  how do we represent the protected access modifier

#

200

class Card { ... }
class Birthday :  Card { ... }
class Holiday : Card { ... }
class NewYear : Holiday { ... }
//Will the following statement(s) compile and if yes what type of casting is applied?
Card card = new NewYear() ;

Yes, it will compile

Card is the parent of Holiday which is the partent of NewYear Pointing to a child object using a parent (or grand parent) pointer is Upcasting.

200

Which statement is true about using method overriding (with virtual) and using abstract methods? Explain.

1. Both do the same exact task but achieve their goal in different ways.
2. Using abstract will force programmers to implement the code of a method.
3. Using method overriding will force programmers to implement the code of a method.
4.They are totally unrelated concepts. 


Using abstract will force programmers to implement the code of a method.

300

A non-static class member with 

a public access modifier an be accessed in..

a private access modifier an be accessed in..

a protected access modifier an be accessed in..

  

public: in class and any other class that creates object of the class.

private: only in the class.

protected: in the class, in any child class and in any child of the child classes

300

In a  UML Class Diagram,  an italic class name indicates ....

an abstract class

300

class Card { ... }
class Birthday :  Card { ... }
class Holiday : Card { ... }
class NewYear : Holiday { ... }
//Will the following statement(s) compile and if yes what type of casting is applied?
BirthDay brd = new BirthDay();
Holiday hd = new Holiday();
NewYear ny = new NewYear();  
ny = brd;

Will provide a compilation error.

ny is a child of Holiday class and cannot be casted to a sibling class (Birthday)

300

class  Sport{
public abstract bool PlayedInTeams();
}

class  Pingpong: Sport {
   public override bool PlayedInTeams()
   { return false ; }
}
On the board create instance of object of Sport and PingPong.

Sport: cannot create because it is abstract.

Pingpong p = new Pingpong();

400

Name and explain the 4 pillars of OOP

Abstraction
Encapsulation
Inheritance
Polymorphism

400

How to indicate static data members in UML

Using underline

400

class Card { ... }
class Birthday :  Card { ... }
class Holiday : Card { ... }
class NewYear : Holiday { ... }
//Will the following statement(s) compile and if yes what type of casting is applied?
Card card = new NewYear();
NewYear ny = card;  

Casting from a Parent pointer to child pointer is downcasting. 

This requires explicit casting. Compiler will provide an error.
NewYear ny = card as NewYear;  

400

abstract class  Sport{
public abstract bool PlayedInTeams();
}

On the board, write class Pingpong that inherits from class Sport.

class  Pingpong: Sport {
   public override bool PlayedInTeams()
   { return false ; }
}