logo codesdope

OOP (Object Oriented Programming in Java)

Welcome to the part of programming for which Java is widely known for : Object Oriented Programming (OOP). To understand this, think of a book having a serial number and a number of pages. Now, your science book is a book as is your computer book. Suppose the serial number of the Science book is SC12 and that of computer book is CS34 and the number of pages are 200 and 250 respectively. It is like in the picture below:

object and class in java

Here book is a class having attributes 'Page' and 'Serial number' with 'Science' and 'Computer' are objects(instances) of it.

So, now you understand that class is something which acts like a base, having some definitions. And objects are instances of the class following those definitions.

One more example of class and objects you can think of is a bank account. Think of 'Account' as a class having attributes 'min_balance' and 'rate_of_interest' and 'Saving' and 'Current' as its objects.

object and class in java

I hope you have got the feel of classes and objects. We will deal with its programming parts in later sections.


You already know what methods are. Methods are of two types - class methods and instance methods.
Class methods - Methods which are defined for a class are class methods.
Instance methods - Methods which are defined for objects are instance methods.

Let's look at an example. Let there be a 'Bike' class and 'bike1' be an object of it. Now, a method 'is_checked' defined in the Bike class to return the checked condition of all the objects of the 'Bike' class is a class method. Another method 'get_model' is defined only for the 'bike1' object to get the model number is an instance method.


Many times, we make a subclass of a class itself. The class whose subclass has been made is called superclass.
All shown methods and attributes of superclass will be shown by its subclass also. And subclass may have some different attributes in addition to those as well. Other names of superclass and subclass are base class and derived class respectively.

In this section, you have been introduced to some concepts of programming. In the following sections, you will go through programming parts.

If you do not practice, you don't deserve to win.
-Andre Agassi

Doubt? Ask question

Welcome.please sign up.


Welcome.please login.