Java Notes - OOPs Concepts
Java Notes - OOPs Concepts
POP vs OOP
OOP concepts
Object oriented programing is a methodology or paradigm to design a program using classed and
objects. It implies the software development and maintenance by providing some concepts.
Object
Class
Encapsulation
Polymorphism
Inheritance
Abstraction
Object : An Object is anything that really exists in the world and that can be distinguished from
others. This definition specifies that everything in this world is an Object.
Identity: Object identity is typically implemented via a unique ID .The value of the ID is not
visible to the external user,but is used internally by JVM to identify each Object uniquely.
For e.g: Pen is an Object .It's name is Reynolds , color is white etc know as its State.
Class : A class is nothing but a blueprint or a template for creating different objects which
defines its properties and behaviors. Java class objects exhibit the properties and behaviors
defined by its class. A class can contain fields and methods to describe the behavior of an object.
The public setXXX() and getXXX() methods are the access points of the instance variables of
the EncapTest class. Normally, these methods are referred as getters and setters. Therefore, any
class that wants to access the variables should access them through these getters and setters.
Adavantages of Encapsulation :
this Keyword
this keyword can be used to refer current class or object instance varaiables (syntax :
this.varibale)
this() can be used to invoke current class constructor
this keyword can be used to invoke current class instance method (implicitly)
(syntax:this.method())
1. Method Overloading
2. Constructor Overloading
3. Operator Overloading (Not supported in Java)
Method Overloading :
Writing number of methods with the same name but signature(means Method-name(arguments))
is different.
Rules or Precautions :
If we specify return type , JVM treats constructor as method without giving error.
The idea behind inheritance in java is that you can create new classes that are built upon existing
classes. When you inherit from an existing class, you can reuse methods and fields of parent
class, and you can add new methods and fields also.
Syntax :
In java programming, multiple and hybrid inheritance is supported through interface only.
When a class extends multiple classes i.e. known as multiple inheritance. For Example: