Difference between class and id | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Difference between class and id

Hello, I want to ask something that confuses me. I'm still confused about the difference between class and id. Can anyone help explain it to me? A code example will really help Sorry for the bad English :( Thanks in advance (Edited)

19th May 2018, 12:11 PM
ArthD
ArthD - avatar
4 Answers
+ 7
Imagine a new cell phone. It has a bar code on the box it came with. When you buy the phone, the cashier scans the bar code, and the system finds out what kind of phone it is, the price, and probably some other things too. It doesn't, however, know exactly what phone it is, from what batch of production it comes from, etc.. Inside the phone is a serial number. This identifies the exact phone, and you can use this information to find info about where and when it was produced, etc. But it won't know the price, or know how many the shop has left of these phones. Bar codes are classes, serial numbers are id's. Classes can be used again, id's cannot.
19th May 2018, 12:38 PM
Øistein Hauge
+ 6
The main difference is class is generic (it is to be applied to multiple similar elements) while id is unique ( only one id once ideally) https://www.sololearn.com/discuss/1018244/?ref=app https://www.sololearn.com/discuss/296093/?ref=app
19th May 2018, 12:17 PM
Sandeep Chatterjee
+ 2
thanks for help :) really helpful
19th May 2018, 12:46 PM
ArthD
ArthD - avatar