Class & Object In Java

SAFIA KHATOONSAFIA KHATOON
1 min read

Class

  • A class is like a blueprint for creating objects.

  • It defines the properties (attributes) and behaviors (methods) that the objects created from the class will have.

Object

  • An object is an instance of a class.

  • It has its own set of properties and can perform actions defined by its class.

Example

  • Class: Car

    • Properties: color, model, speed

    • Methods: start(), stop(), accelerate()

  • Object: myCar (an instance of the Car class)

    • Properties: color = red, model = "Toyota", speed = 0

    • Methods: myCar.start(), myCar.stop(), myCar.accelerate()

In simple terms, think of a class as a recipe and an object as the actual dish made using that recipe.

0
Subscribe to my newsletter

Read articles from SAFIA KHATOON directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SAFIA KHATOON
SAFIA KHATOON

Hi! My name is Safia Khatoon. I am complete my Bachelors in Technology from RTC Institute Of Technology. My specialisation in Computer Science and Engineering.I love contributing to Open Source with the help of the skills I gain. Also, I'm working on my YouTube Channel as well where I teach about DevOps tools and make technical content. You can have a look at it through my profile. Feel free to reach out to me! I'd be happy to connect with you.