OOPS Unit2 Firsthalf Updated
OOPS Unit2 Firsthalf Updated
Output
sum of a and b is 5
sum of a and b is7
2) Method Overloading: changing data type
of arguments
Object as Parameters
Output
Sum of a and b :13
Returning Objects:
A method can return any type of data, including class types that you create.
Output:
nice fruits
Local inner class
Output:
30
Inheritance:
• Definition1:
• Inheritance in Java is a mechanism in which one
object acquires all the properties and behaviors
of a parent object. It is an important part of
OOPs (Object Oriented programming system).
• Definition2:
• The process of deriving new from existing class
by sharing the properties of existing class is
known as inheritance.
• The new class that is created is known
as subclass (child or derived class) and the
existing class from where the child class is
derived is known as superclass (parent or base
class).
Why use inheritance in java
• For Code Reusability
The syntax of Java Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}
Member Access and Inheritance
• 1.Single
• 2.Multiple
• 3.Multilevel
• 4.hierarchial
• 5.hybrid
Single Inheritance
Multiple Inheritance