📅  最后修改于: 2020-09-23 10:52:15             🧑  作者: Mango
对象和类之间有许多区别。对象和类之间的差异列表如下:
No. | Object | Class |
---|---|---|
1) | Object is an instance of a class. | Class is a blueprint or template from which objects are created. |
2) | Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. | Class is a group of similar objects. |
3) | Object is a physical entity. | Class is a logical entity. |
4) | Object is created through new keyword mainly e.g. Student s1=new Student(); |
Class is declared using class keyword e.g. class Student{} |
5) | Object is created many times as per requirement. | Class is declared once. |
6) | Object allocates memory when it is created. | Class doesn’t allocated memory when it is created. |
7) | There are many ways to create object in java such as new keyword, newInstance() method, clone() method, factory method and deserialization. | There is only one way to define class in java using class keyword. |
让我们看一下Java中类和对象的真实示例,以更好地理解它们之间的区别:
类别:人类对象:男人,女人
类:水果对象:苹果,香蕉,芒果,番石榴wtc。
类别:手机对象:iPhone,三星,Moto
类:食品对象:比萨,汉堡,萨摩萨