Object-Oriented Programming – What is a Class?

Object Oriented Programming - What is a Class

Liked this Post?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on reddit
Share on Reddit
Share on linkedin
Share on LinkedIn
Share on whatsapp
Share on WhatsApp
Share on telegram
Share on Telegram

A Class can be thought of as the blueprint of an Object.

Think about a house blueprint. You can’t live in it, but you can build a house from it, which means you build an instance of it. An Object is an instance of  a Class.

So what exactly is a class? it is a bunch of code that can contain methods, variables, loops, and all other types of code syntax.

[box type=”info” align=”” class=”” width=””]As a convention Class names should be Proper cased and Camel cased[/box]

The following code defines a ‘Car’ class

// Java Code 
class Car{
 private String name; // member variable
 private String color;// member variable
 private int topSpeed;// member variable

//Constructor of a Class
 public Car(String name, String color, int topSpeed) { = name;
 this.color = color;
 this.topSpeed = topSpeed;
In object-oriented programming, a Constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.
// Kotlin Code. You Should learn Kotlin! it's concise
class Car(val name: String, val color: String, val topSpeed: Int)


from the above classes we can create many types of Car object from the ‘Car’ Class and define different characteristics for each.

we could do the following to Create an Object from our Defined Class.

//in java 
Car car1 = new Car ("polo", "Green",  200);
Car car2 = new Car ("mini", "Blue",  185);
Car car3 = new Car ("beetle", "Red",  165);
val car1 =  Car ("polo", "Green",  200)
val car2 =  Car ("mini", "Blue", 185)
val car3 =  Car ("beetle", "Red",  165)

car1, car2, car3 are our objects from’Car’ class.

Now we know that all Cars should posses the ability to accelerate which leads us to Functions (or Methods)


[box type=”shadow” align=”” class=”” width=””]

Further Reading:

What is Object-Oriented Programming?




About the Author

Edge Developer

Edge Developer

Hello there, my name is Opeyemi Olorunleke. I am a Software Developer (majorly Android, GitHub Profile), Digital Marketer, Udemy Instructor, Technical Writer, Blogger & Webmaster.

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *