Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

Hi! I'm taking a course on JAVA, and i dont understand what a class is. Why do we have them and what do they do? Can someone help me please!

OpenStudy (e.mccormick):

The term template applies. This is in the Java documentation: https://docs.oracle.com/javase/tutorial/java/concepts/class.html As it says there, it is like a blueprint for making objects. Lets take a playing card from a dec of cards. It has a certain shape that all the cards will have. It has a suit, there are only four, and a value, of which there are thirteen. If you need to make just the standard cards, it will always be within those limits. For a computer game of cards, you might use the size to define how it will be drawn on the screen. That basic allocation of size will be the same for all cards. They template for the cards would have that and places to store the suit and value. This template would be a class file for the cards.

OpenStudy (anonymous):

so would each type of card have its own template?

OpenStudy (e.mccormick):

Generally, no. If it is a deck of cards, the template would be for a card, which is enough. I made a space game for a school project once. I made a template for objects in space. Then, I made a child of this template that was for asteroids and used that scild template to make lots of asteroids. In this way, I wrote the fact that things needed an x/y positon, alive/dead, and associated image once. The asteroids only needed that much, as did missiles. The player also needed a little more, like total number of lives remaining and speed. oops... yah, asterpoids also had speed, it went up each level... anyhow, it made it so I rewrote the code less because each class was a sub class of the object class and inherited the basic properties needed.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!