The word 'class' is used very loosely in Java tutorials and study material. There are many many different meanings to this word. Can some body please enumerate and explain all meanings of this word. E.g.: 'class' means an object, 'class' is an file extension, 'class' is the first word used in declaring object, etc.
Class is an object-oriented term. A class is a description of a set of objects, the common behaviour they have and the state they have. Classes can inherit state and behaviour from superclasses. To put this another way:
Human is a class. Humans have state:
- Eye colour;
- Skin colour;
- Type and colour of hair;
- Height;
- Weight;
- and so on.
and behaviour:
- Walk;
- Run;
- Swim;
- Eat;
- Drink;
- etc.
Human has two subclasses in this example: Man and Woman. They have all the state and behaviour of Human but also some state and behaviour unique to each, like the obvious anatomical differences as state and behaviour as, for example, women can have babies.
An object is an instance of a slass. To put this another way: Megan Fox is an instance of the class Woman. Being a Woman, she is also an instance of the superclass Human.
As for Java, it generates one .class file for each class encountered when it compiles source code. Source files can contain multiple class files.
- class describes the blueprint or prototype from which objects are created.
- object is an individual instance or unit of that class
A file can have several classes but just one public. The public one has to be the same name as the file for e.g public class Car - has to be Car.java.
You should name your classes starting with an uppercase and objects starting with an lowercase. A class contains a set of variables which tell you the state of a object from this class. A class contains a set of methods which tell you the behavior of the objects.
A class is like a describtion from one or more similar objects. A object is an instance of that class. You can have a Class Car with the variables speed, color, name. Then you can make for e.g. 2 objects peugeot and a porsche. Both can have diffrend speed, color and a name. You can make as many cars as you want by making a object from the class Car.
There are many many differnt meanings to this word.
No. There is exactly one meaning:
- A class is a blueprint for object instances
- You define such a blueprint in your Java source code by using the 'class' keyword
- The Compiler will turn your source code into byte code files - one file with the extension .class for each class in your source code
There are different places where the word "class" occur, but they are all related to the same basic meaning. Or are you also confused by the fact that "World of Warcraft" is a game you bought in a store, a shortcut on your desktop, and the name of a folder on your harddisk?
There is a keyword "class" use to define a class in Java. There is a "Class" class which is the parent class of all classes. And there is a ".class" which is a file extension.
You should be able to determine which is which from context.