Classes And Objects Flashcards

1
Q

What is a class?

A

A blueprint or template for creating objects. It defines the properties (fields) and behaviors (methods) that the objects will have.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an object?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create an object from a class?

A

Use the new keyword followed by a constructor of the class.
(MyClass obj = new MyClass();)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a constructor?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the ‘this’ keyword?

A

The ‘this’ keyword refers to the current instance of the class. It is used to distinguish instance variables from parameters with the same name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly