Check the UML class diagram.
Write the code for the child class.
PingPong(string name) : base(name)
{ ..}
In a UML Class Diagram, the (+) plus sign indicates:
public
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
Can an abstract class define both abstract methods and non-abstract methods?
Yes.
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.
In a UML Class Diagram, how do we represent the protected access modifier
#
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.
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.
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
In a UML Class Diagram, an italic class name indicates ....
an abstract class
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)
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();
Name and explain the 4 pillars of OOP
Abstraction
Encapsulation
Inheritance
Polymorphism
How to indicate static data members in UML
Using underline
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;
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 ; }
}