Difference between Class and Object in Java and OOPS with Example

Class and Object are two most important concept of Object oriented programming language (OOPS)  e.g. Java. Main difference between a Class and an Object in Java is that class is a blueprint to create different objects of same type. This may looks simple to many of you but if you are beginner or just heard term Object Oriented Programming language it might not be that simple. I have met many students, beginners and programmers who don’t know difference between class and object and often used them interchangeably. Also Java API having classes like java.lang.Object and java.lang.Class also adds more confusion in beginners mind. Both of them are totally different things, class and object in OOPS are concepts and applicable to all Object oriented programming language e.g. C++ or Scala. On the other hand java.lang.Class and java.lang.Object are part of Java API. Along with other OOPS concepts like Abstraction, Encapsulation, Inheritanceand Polymorphism, this is also one of the most fundamental of Object oriented programming (OOPS) which needs to be clearly understood before proceeding into serious application programming. Without clear understanding of Class and Object you are more prone to make errors, not able to comprehend an already written program and it would be pretty hard for you to find bugs or fix errors or exceptions in Java code. By the way difference between class and object is also a popular programming interview question, which is quite frequently asked at fresher level interviews.  In this article we will look this on different angles to differentiate Class and object in Java. Once you get hold of key OOPS concepts, I would recommend to read 10 OOPS and SOLID design principles for Java programmer, which is tried and tested design pattern for writing better code.
Read more »