0% found this document useful (0 votes)
4 views

self-java

Uploaded by

Santhosh Dany
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

self-java

Uploaded by

Santhosh Dany
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Need for OOP paradigm:

• The object oriented paradigm is a methodology for producing reusable


software components.

• The object-oriented paradigm is a programming methodology that promotes


the efficient design and development of software systems using reusable
components.

• Object oriented programming is a concept that was created because of the


need to overcome the problems that were found with using structured
programming techniques. While structured programming uses an approach
which is top down, OOP uses an approach which is bottom up.

The Object-Oriented Programming (OOP) paradigm provides several benefits,


including:

1. *Modularity*: OOP allows for modular design, making it easier to maintain


and update code by breaking it into smaller, manageable parts called objects.

2. *Reusability*: Objects can be reused across different parts of a program or


even in different programs, reducing redundancy and promoting code reuse.

3. *Encapsulation*: OOP encapsulates data and methods within objects, hiding


internal implementation details and providing clear interfaces for interacting
with those objects.

4. *Abstraction*: OOP allows for the abstraction of complex systems, focusing


on essential details while hiding unnecessary complexity, which enhances code
readability and maintainability.

5. *Inheritance*: Inheritance enables the creation of new classes based on


existing ones, facilitating code reuse and promoting a hierarchical organization
of code.

6. *Polymorphism*: Polymorphism allows objects of different classes to be


treated uniformly through inheritance and interfaces, promoting flexibility and
code extensibility.
Overall, the OOP paradigm helps improve code organization, readability,
maintainability, and scalability, making it a popular choice for software
development

Method Overriding:
If a child class has the same method which is already defined in its parent class,
then it is known as method overriding in Java.

Rules for Java Method Overriding


1. The method must have the same signature as in the parent class. The means
the overloaded method should have same name, same parameters and same
return type.

2. There must be an IS-A relationship between the classes.

Usage of Java Method Overriding :


1. Method overriding is used to provide specific implementation for child class
method which is already defined by its parent class.
2. Method overriding is used for runtime polymorphism.

Note: -
1. A static method cannot be overridden. Because static method is bound with
class whereas instance method is bound with object. Static belongs to class
area and instance belongs to heap area.
2. We cannot override main() method because main() is a static method.
Overloading Methods:
• The Java programming language supports overloading methods, and Java can
distinguish between methods with different method signatures. This means
that methods within a class can have the same name if they have different
parameter lists.

• In the Java programming language, you can use the same name for all the
drawing methods but pass a different argument list to each method. Thus, the
data drawing class might declare four methods named draw, each of which has
a different parameter list.

• Overloaded methods are differentiated by the number and the type of the
arguments passed into the method.

• You cannot declare more than one method with the same name and the
same number and type of arguments, because the compiler cannot tell them
apart.

• The compiler does not consider return type when differentiating methods, so
you cannot declare two methods with the same signature even if they have a
different return type.

• Overloaded methods should be used sparingly, as they can make code much
less readable.

Constructors:
1.A constructor is a special member function.
2.A constructor is similar to class name.
3.A constructor is invoked automatically whenever an object is created.
4.A constructor has no return type; not even void.
5.It cannot be abstract, final, native, static or synchronized.
Constructors are classified into 3 types:
They are:
1.Default con/ No argument con.
2.Parameterized con/ argument con.
3.Overloaded con.
Default constructor:
A constructor function without having parameters, those constructors are
called as default constructors or non-parameterized constructor.
Ex:
Class example
{
Int p,q;
Example()
{
P=10;
Q=20;
}
}

Parameterized constructor:
A constructor function having parameters, those constructors are called as
parameterized constructors.
Ex:
Class example
{
Int p,q;
Example(int x, int y)
{
P=x;
Q=y;
}
}

overloaded constructor:
A constructor contain more then one constructor function, those constructors
are called as overloaded constructors.
Ex:
Class example
{
Int p,q;
Example()
{
P=10;
Q=20;
}
Example(int x, int y)
{
P=x;
Q=y;
}

You might also like