0% found this document useful (0 votes)
40 views9 pages

VB Day 4

Inheritance allows classes to reuse and modify existing class definitions. .NET supports single and multi-level inheritance. Members defined as public or protected in the base class can be accessed directly in derived classes. Method overriding modifies base class member definitions in derived classes by prefixing with "overrides". Methods must be marked as "overridable" in base classes to be overridden in derived classes. Shadowing uses derived class method definitions instead of base class definitions by prefixing with "shadows". Multiple inheritance is not possible in .NET as a class cannot inherit from more than one parent class.

Uploaded by

Fenil Desai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

VB Day 4

Inheritance allows classes to reuse and modify existing class definitions. .NET supports single and multi-level inheritance. Members defined as public or protected in the base class can be accessed directly in derived classes. Method overriding modifies base class member definitions in derived classes by prefixing with "overrides". Methods must be marked as "overridable" in base classes to be overridden in derived classes. Shadowing uses derived class method definitions instead of base class definitions by prefixing with "shadows". Multiple inheritance is not possible in .NET as a class cannot inherit from more than one parent class.

Uploaded by

Fenil Desai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Inheritance

• It is used to reuse or redefine the existing class


definitions.
• Note:.net supports single and multi-level
inheritance .
• If a class inherits other class then the members
of the class which are defined using
public,protected,friend modifiers can be
accessed directly from the derived class.
Inheritance

Parents Base Class

myProperty() Public

Children Derived Class

myProperty()
Syntax for Inherit a Class
• Class derivedclassName
inherits baseclassName
member(s) / ‘statements
end class
• 2nd syntax
class derivedclassName : inherits baseclassName
(this should be in the same line)
member(s) / ‘statements
end class
{see example}
Method Overriding
• When ever the base class members
definitions are modified at the derived class
then it is said to be method overriding.
• [or in another words] like if I have a
definitions in base and I am changing it in
the modifying it is derived class then this is
called as method overriding.
Points to remember for method
overriding
• In order to override a method definition at the
derived class it should be prefixed with
“overrides” keyword.
• If a method is prefixed with overrides keyword at
the derived class then it is a mandatory to define
that method using “overriadable” keyword at the
base class.
• If a method is prefixed with “overriadable”
keyword at the base class it is not mandatory to
redefine that method from the derived class.
SHADOWING
• It is used to shadow the method definitions specified at the derived
class.Such that the definitions specified at the base class can be used.

Parents

myProperty() Use property for


property

Children

Shadows Use property for


myProperty()
charity
• Note  if an object is defined for the
derived class and if there is any method
shadowed with in it then always the
definition provided by the derived class will
be provided.
• Dim c as new childern()
– C.myProperty()
– Use property for charity
• In order to get the definition from the base class which has
been shadowed in the derived class to do 
– Define a variable for the base class
– Assign the derived class object or create an instance for the
derived class object with reference to the base class variable.
– Refers the members using the base class variable
– For eg:
• Dim P as parents
• P = C ‘ where c is a derived class object
• P.myproperty()
• Whenever the method is shadowed in the derived class it is
not mandatory to say “Overridable” at the base class for
that method definition.
– The base class trusts the derived class in shadowing ie parents trust
the child
MULTIPLE INHERITANCE NOT
POSSIBLE
Fathers (class) Mother(class)

Public myProperty() Public myProperty()

This is not possible in Children NOT


.net as we r trying to add POSSIBLE
2 properties with same myProperty()
name
myProperty()

You might also like