Udacity OOJava Flashcards

1
Q

What is a constructor?

A

special types of methods that are responsible for creating and initializing an object of that class

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

How do you create a constructor?

A

Same as methods except:

  • Constructors don’t have any return types
  • Constructors have the same name as the class itself

They can however take input parameters like a normal method, and you are allowed to create multiple constructors with different input parameters.

class Game{
   ...
   // Constructor
   Game(){
      // Initialization code goes here
   }
   ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a default constructor?

A

doesn’t take any input parameters at all!

if you don’t create a default constructor, Java will automatically assume there’s one by default that doesn’t really do anything.

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

Loops
What is the shorthand for?
i++;

A

i = i+1;

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

Loops
What is the shorthand for?

i = i-1;

A

i–;

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

Loops
What is the shorthand for?

i = i+5;

A

i += 5;

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

Loops
What is the shorthand for?

i = i-6;

A

i -+ 6;

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