2. What
Is
Inheritance
Inheritance can be defined as the process
where one class acquires the properties
(methods and fields) of another. With the
use of inheritance the information is
made manageable in a hierarchical order.
The class which inherits the properties of
other is known as subclass (derived
class, child class) and the class whose
properties are inherited is known as
superclass (base class, parent class).
3. Types
Of
Inheritance
There are various types of inheritance, based
on paradigm and specific language :
● Single Inheritance
● Multiple Inheritance
● Multilevel Inheritance
● Hierarchical inheritance
● Hybrid Inheritance
6. Advantage
Of
Inhetitance
Advantages of Inheritance :
- It Allows the code to be reused as
many times as needed.
- The base class once defined and once
it is compiled, it need not be reworked.
- Saves time and effort as the main code
need not be written again.
9. Characteristics
of
Constructors
● Their name is same as that of the class
whose member they are.
● They do not have any return type, not
even void.
● They can be explicitly defined by the
programmer.
● They are provided by the compiler if
not defined explicitly.
● They are called automatically when an
object is being created or copied.
● They can be overloaded
10. Types
Of
Constructor
❏ Default Constructor:
class Demo
{
public Demo()
{
}
}
* There are no parameter
❏ Parameterized Constructor:
class Demo
{
public Demo(int num, String str)
{
}
}
* There are two parameter
12. What
Is
Friend Function
Friend class a friend class can
access private and protected
members of other class in
which it is declared as friend.
It is sometimes useful to allow a
particular class to access
private members of other class.
14. Some
Important Point
About
Friend Function
1) Friends should be used only for limited purpose.
too many functions or external classes are declared
as friends of a class with protected or private data, it
lessens the value of encapsulation of separate
classes in object-oriented programming.
2) Friendship is not mutual. If a class A is friend of B,
then B doesn’t become friend of A automatically.
3) Friendship is not inherited
4) The concept of friends is not there in Java.