Skip to content

Java OOPs Concepts

EWriter edited this page Dec 25, 2021 · 1 revision

Class - the blueprint from which individual objects(instances of objects) are created. Fields - represent the object's state Methods - define its interaction with the outside world. Methods form the object's interface with the outside world;

Different kinds of objects often have a certain amount in common with each other. Yet each also defines additional features that make them different. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

inherit - Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

superclass - parent class. each class can only have one direct(?) superclass. a superclass can have unlimited subclasses

subclass - child class

extends - keyword used to create a subclass class MountainBike extends Bicycle {

// new fields and methods defining 
// a mountain bike would go here

}

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

implements

Java OOP System

Object - Any entity that has state and behavior Class - Collection of objects Inheritance - When one object acquires all the properties and behaviors of a parent object Polymorphism - If one task is performed in different ways. In Java, we use method overloading and method overriding to achieve polymorphism. Abstraction - Hiding internal details and showing functionality is known as abstraction. For example phone call, we don't know the internal processing. In Java, we use abstract class and interface to achieve abstraction. Encapsulation - A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here. Binding (or wrapping) code and data together into a single unit are known as encapsulation.

Coupling - If a class has the details information of another class, there is strong coupling. In Java, we use private, protected, and public modifiers to display the visibility level of a class, method, and field. You can use interfaces for the weaker coupling because there is no concrete implementation. Cohesion - A single well-defined task is done by a highly cohesive method. The weakly cohesive method will split the task into separate parts. Association - the relationship between the objects.

  • One to One One to Many Many to One, and Many to Many Aggregation - a way to achieve Association. Aggregation represents the relationship where one object contains other objects as a part of its state. It represents the weak relationship between objects. It is also termed as a has-a relationship in Java. Like, inheritance represents the is-a relationship. It is another way to reuse objects. Composition - also a way to achieve Association. The composition represents the relationship where one object contains other objects as a part of its state. There is a strong relationship between the containing object and the dependent object. It is the state where containing objects do not have an independent existence. If you delete the parent object, all the child objects will be deleted automatically.

Clone this wiki locally