Class / Object in OOPs

Class / Object in OOPs

I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming concept here in a simple and easy way from my experience. This will be very useful for beginner Devs and Students.

We have seen ladder of OOPs concept in previous article now in this article, we will learn about class and object in oops.

What is a class in Java

  • A class is a blueprint or template for creating objects.
  • It defines the attributes (fields/variables) and behaviors (methods/functions) that objects of that class will have.
  • Classes encapsulate data for the objects, along with methods to operate on that data.
  • In Java, a class is declared using the class keyword followed by the class name.

Example of a simple class in Java:

class object in java

What is an object in Java

  • An object is an instance of a class. It's a real-world entity that has a state and behavior.
  • Objects are created from classes using the new keyword, which invokes a constructor to initialize the object.
  • Each object has its own set of attributes (fields) and can perform actions (methods) defined in its class.

Example of creating and using objects in Java:

class object in java

In this example, Person is a class that represents person. We create two person objects (object1 and object2) using the new keyword. Then, we access their fields and call their methods.

That's it for now.

Thanks,

Stay tuned for another chapter on OOPs Concept.




Sanjukta Majumdar

looking for opportunity

11 个月

I learn

Thanks for sharing... Great explanation of the concept of class and objects in oops.

Nikhil Khant

Team Leader | Sr. Android Developer | Java | Kotlin | Roku Tv developer | Amazon Fire stick

11 个月

Thanks for sharing

Dharshan Kumar

Aspiring Java Developer | Core Java, Spring Boot, Hibernate,MySQL,JPA,

11 个月

Waiting for next chapter??

Hardik Jadav

Student at GTUPGSCHOOL

11 个月

Thank you for Posting

要查看或添加评论,请登录

Naimish Trivedi的更多文章

  • Load a thumbnail image of a PDF file using Glide.

    Load a thumbnail image of a PDF file using Glide.

    I am Naimish Trivedi, I have a vast experience in native and cross platform programming. I have presented the Android…

    5 条评论
  • What are the Differences Between KSP and KAPT in Android?

    What are the Differences Between KSP and KAPT in Android?

    I am Naimish Trivedi, I have a vast experience in native and cross platform programming. I have presented the Android…

    1 条评论
  • Launch modes in Android

    Launch modes in Android

    I am Naimish Trivedi, I have a vast experience in native and cross platform programming. I have presented the…

    2 条评论
  • The Art of Object Encapsulation

    The Art of Object Encapsulation

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    2 条评论
  • Abstraction in OOPs

    Abstraction in OOPs

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    3 条评论
  • Magic of Polymorphism in Object-Oriented Programming

    Magic of Polymorphism in Object-Oriented Programming

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    1 条评论
  • Building Hierarchies: Mastering Inheritance in OOPs

    Building Hierarchies: Mastering Inheritance in OOPs

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    2 条评论
  • OOPs Concept Ladder

    OOPs Concept Ladder

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    10 条评论
  • Lateinit vs Lazy in Kotlin

    Lateinit vs Lazy in Kotlin

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    5 条评论
  • Introduction of OOPs concept

    Introduction of OOPs concept

    I am Naimish Trivedi, I have a far experience in native and hybrid programming. I have presented the programming…

    4 条评论

社区洞察

其他会员也浏览了