- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between Object and Class in Java
Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors – wagging the tail, barking, eating. An object is an instance of a class.
Class - A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support.
In the following example, Pummy is a class and myPuppy is an object.
public class Puppy { public Puppy(String name) { // This constructor has one parameter, name. System.out.println("Passed Name is :" + name ); } public static void main(String []args) { // Following statement would create an object myPuppy Puppy myPuppy = new Puppy( "tommy" ); } }
If we compile and run the above program, then it will produce the following result.
Output
Passed Name is :tommy
- Related Articles
- Difference between Object level lock and Class level lock in Java
- Difference Between Object and Class in C++
- Difference between String class and StringBuffer class in Java
- Difference between a "class" and an "object" in Kotlin
- Difference Between Class and Interface in Java
- Difference between Abstract Class and Interface in Java
- Difference between Scanner and BufferReader Class in Java
- Difference Between String and StringBuffer Class in Java
- Difference Between Thread Class and Runnable Interface in Java
- Difference Between Interface and Abstract Class in Java & C#
- What is the difference between Component class and Container class in Java?
- Object and class in Java
- What is the difference between a class and an object in C#?
- What is the difference between abstract class and a concrete class in Java?
- What is the difference between object and reference in java?

Advertisements