You are on page 1of 21

Module 3

Params:

EX:
O/P:

Parameter array and optional parameters:


Ex:
Single level Inheritance:
Hierarchical Inheritance:

Multiple Inheritance:
Multilevel Inheritance:
Method Hiding & Method Overriding: (new, virtual, override keywords)

✓ For hiding the base class method from derived class simply declare the derived class
method with new keyword.

✓ In C#, for overriding the base class method in derived class, you have to declare base
class method as virtual and derived class method as override.

✓ You can also mix the method hiding and method overriding by using virtual and new
keyword since the method of a derived class can be virtual and new at the same time.
This is required when you want to further override the derived class method into next
level as I am overriding Class B, Test () method in Class C as shown below:

Ex:
Limiting Accessibility in Inheritance (using Protected):
Protected keyword gives accessibility to the members of base class and
child/derived classes only.
INTERFACE:
Important Points:
• Generally, we use abstract class at the time of inheritance.
• A user must use the override keyword before the method which is declared as
abstract in child class, the abstract class is used to inherit in the child class.
• An abstract class cannot be inherited by structures.
• It can contain constructors or destructors.
• It can implement functions with non-Abstract methods.
• It cannot support multiple inheritance.
• It can’t be static.

SEALED CLASS:
EX:

o/p:
➔ Methods and classes can be sealed but not local variables.

Ex for Sealing a method:


Difference between Interface and Class:

GARBAGE COLLECTOR AND RESOURCE MANAGEMENT:


Advantages of GC:

(//write selected points from above…. understand & write in your own words)
(// understand all of above and write necessary points…concepts above all are important)
EX:
OR (can write below one for garbage collection & resource
management)
----------------------------------------------END---------------------------------------------------
NOTE:
For method over-riding same example of abstract class can be used.
Hhrpkpmcc…..ATB!

You might also like