1
0

Class Basics in Java

Java is a pure object-oriented language and therefore supports the concepts of Object-Oriented Programming Language. Java’s basic concepts like class, object, encapsulation, inheritance, and polymorphism are being discussed here briefly for your reference.

Class:

A class is a user-defined data type that contains both data (referred to as attributes or fields), and executable code (referred to as methods). Sometimes a class is also referred to as object factory or set of objects since it is used to create objects.

Object:

The central concept of object-oriented programming is the object, which is a kind of module containing data and subroutines. The point-of-view in OOP is that an object is a kind of self-sufficient entity that has an internal state (the data it contains) and that can respond to messages (calls to its methods) showing a particular behavior.

Encapsulation:

Encapsulation is the mechanism of hiding the state data of the object from unauthorized access, by providing access through member methods. In Java encapsulation is achieved by declaring the instance variable as private and member methods as public.

Inheritance:

Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance, the information is made manageable in a hierarchical order of classes. More specifically, in inheritance, the Child class (Derived class) inherits the properties of the Parent class (Base class).

Polymorphism:

Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. For example suppose we have area() method defined for Circle, Rectangle, and Triangle classes then the method area() will respond differently for different classes by giving different results. Here method has the same name but does different activities for different objects.

We will further elaborate on these concepts with Java code in the next part of the course.

Leave a Reply