Classes And Objects Flashcards
What is a class?
A blueprint or template for creating objects. It defines the properties (fields) and behaviors (methods) that the objects will have.
What is an object?
An instance of a class. It contains the actual values for the fields defined in the class, and can call methods that the class defines.
How do you create an object from a class?
Use the new keyword followed by a constructor of the class.
(MyClass obj = new MyClass();)
What is a constructor?
A special method used to initialize objects when they are created. It has the same name as the class and does not return a value.
What is the purpose of the ‘this’ keyword?
The ‘this’ keyword refers to the current instance of the class. It is used to distinguish instance variables from parameters with the same name.