Oops concept in Java

Object-Oriented Programming (OOP) uses “objects” to model realworld objects. Object- oriented Programming (OOP) consist of some important concepts namely Encapsulation, Polymorphism, Inheritance and Abstraction. These features are generally referred to as the OOPS concepts. OOPs

Object-Oriented Programming is a concept to design a program using object and classes.

An object in OOP has some state and behavior. In Java, the state is the set of values of an object’s variables at any particular time and the behaviour of an object is implemented as methods. Class can be considered as the blueprint or a template for an object and describes the properties and behavior of that object, but without any actual existence. An object is a particular instance of a class which has actual existence and there can be many objects (or instances) for a class. Static variables and methods are not purely object oriented because they are not specific to instances (objects) but common to all instances.

Classes

Acting as blueprints of a Java program, classes are templates that describe the characteristics of an element or method. They are generic elements in Java programming. They also help a programmer to understand the coding system of another programmer, making its structure clear. Classes exist in the program as long as they desire, meaning they do not have a lifespan.

The following is a list of possible class variables:

  • Class

    A class is a variable that needs to be declared before it enters a class, which can be found within any class and outside any method.

  • Instance

    Instance is a variable that remains within a particular class but is outside a method. However, it is accessible from any other way once declared.

  • Local

    A local is a variable that is defined inside any method in the program and requires initial declaration and acknowledgement. It is omitted after it has executed the command or function.

Objects

Java objects are elements that possess behaviours and states. When parts are defined, they come with their features that further adds value to a program component without having to include an extensive element. These are what you call instances of classes. Because of the behaviours and states of objects, methods are executed successfully. Furthermore, a particular item is associated with a unique function or command so that it will adhere to specific instructions. In contrast with a class, an object ceases to exist once the program has been executed.

One of the characteristics of object-oriented programming is organizing things and concepts. Three object relationships define why elements should or should not be moved to another particular program component:

  • Is-a Relationship – this means that a type of object is more specific than its fellows (number 1 is a number)
  • Has-a relationship – this means that a variety of object contains or is associated with another object (given number 1 and number 2: number 1 has a succeeding number, number 2)
  • Uses-a relationship – this means that a type of object will be using another object as a program progresses (given number 1, number 2 and number 3:

number 1 uses a number 2 to arrive at the sum of number 3)

It is essential to know how to work around with classes and objects when programming using the Java language since they are considered as the generic elements of the software. We also learned how they are organized and their existing relationships with one another.

Copyright 1999- Ducat Creative, All rights reserved.