Java OOPS Concepts
Object oriented programing language provides many concepts, such as Inheritance, Data Binding, Polymorphism etc.
Any entity which has state and behavior is known as object. It can be physical or logical part. For example, a chair, pen, keyboard etc.
An object can be define as instance of class. An object contains an address and takes up some space in memory. Objects can communicate with each other without knowing the details of each others data or code. Only the type of response and message acceptance is important. The representation of object is same as below:
Class:
Class is a collection of object. It is logical entity. Class can also be define as a blueprint from which you can create individual object. Class doesn't consume any space. Sample example of java class declaration is as follows:
class SampleDemo{
// Statements or logical code
// variable declaration with its data types
// methods delaration and definitions
public static void main(String args[]){
// Statements or logical code
// variable declaration with its data types
// methods delaration and definitions
}
}
- The first line 'class SampleDemo' declares a class, which is object oriented construct.
- Every class having the opening braces '{' and the closing braces '}' and it is call delaration of class.
- Every class has the 'main()' method. It is a starting point of execution of program.
- The public is a keyword call access specifier which declare that it is unprotected and access from any other class. (We will discuss access specifiers in later sections)
- The static keyword is declare that method is one part of entire class not a part of any object of class. (We will discuss this in later sections)
- The type modifier void is defines that methods does not returns any value.
Inheritance:
Inheritance is the process by which objects of one class can acquires the properties of object of another class in other words, when one object/class can acquires all the properties of parent object/class, it is known as inheritance. It provides code reusability and use to achieve runtime polymorphism.
Ploymorphism:
If any object have more than one form in other words, if one task is perform in different ways, it is known as polymorphism. In java method overloading and method overriding is use to achieve polymorphism. An example, an operation may clearly different behavior in different instance. The main behavior is depend on type of a data use in operation.
Abstraction:
Abstraction refers to the act of representing essential features without including the background details or explanations. In other word, Hiding internal details and showing functionality is known as abstraction. Classes use the concept of abstraction and define as a list of abstract attributes such as size, weight, cost and methods that operates on the attributes. We use abstract class and interface to achieve abstraction.
Encapsulation:
Binding or wrapping of code/method and data together into a single unit known as encapsulation. Data encapsulation is most striking features of class. The data is not accessible outside the world, and only methods which are wrapped in the class can access it. These method can provide interface between object's data and program. Java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.
Coupling:
Coupling refers to the knowledge or information or dependency of another class. If class has the detail information of another class, there is strong coupling. In java, we use public, private, protected and default modifiers to display the visibility of class, method and variable/field. We can also use interface for weaker coupling because there is no concreate implementation.
Association:
Associations represents the relationship between the objects. One objects can associates with one object or many objects. There are four type of association between objects:
- One to One
- One to Many
- Many to One
- Many to Many
Comments
Post a Comment