-7

Can someone please explain me difference between Class class object and object of a class in Java.If possible with a simple example.

amit
  • 3
  • 2
  • 1
    Could you give an example of code of which you want an axplanation? – Bart Friederichs May 25 '18 at 07:56
  • 2
    @Lino - Possibly, although my read of the above is that it's asking about the object for the class (e.g., `String.class`). It's just too vague to know. Good link regardless. – T.J. Crowder May 25 '18 at 07:59
  • This has been explained well in many places — also better than you should expect from an average Stack Overflow answer (sorry). If there is something you don’t understand in those explanations, or something specific you would like us to add, ask a much more specific question. – Ole V.V. May 25 '18 at 08:33

2 Answers2

1

Objects of type Class represent the definition of a class.

Objects of some Class are, well, the objects of that class.

Objects of type (/class) Customer represent customers.

Object(s) of type Class represent the definition of what the objects of type (/class) Customer look like internally in your system.

Erwin Smout
  • 18,113
  • 4
  • 33
  • 52
  • And `Object.class` is a static reference of an instance `Class`, defining the class of `Object`. – AxelH May 25 '18 at 08:06
0

Class is something like template or map that you can use to create product. Object at other hand is a product created based on that template.

For example you can have Car template, this template isn't a car and you can't drive it. It just say how to create new Car.

class Car {
     // some filed or method here
}

But Object of that class is actual car that you can drive.

Car carInstance = new Car(); // here we create carInstance based on Car template (Class)

If access Car class you access it's template properties, like fields, methods or constructors.

Class<Car> carClass = Car.class;

and for example get it's fields :

Field [] fields = carClass.getFields();
Esterlinkof
  • 1,444
  • 3
  • 22
  • 27