Variables Flashcards

1
Q

What is a variable?

A

A name that labels a value. It gives us a way to remember what is being stored.

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

What is a variable’s scope? Discuss the three main types.

A

Scope defines where a certain variable or method is accessible in a program. Variables can be defined as having one of three types of scope:

1) Class level scope (instance variables): any variable declared within a class is accessible by all methods in that class. Depending on its access modifier (ie. public or private), it can sometimes be accessed outside the class.
2) Method level scope (local variables): any variable declared within a method, arguments included, is NOT accessible outside that method.
3) 3) Block scope (loop variables): any variable declared in a for loop condition is not accessible after the loop, unless you defined it beforehand.

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

What is a literal? Give examples.

A

A literal is “any notation for representing a value within source code”

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

What happens if you define a variable without assigning a value, and then use the variable?

A

Error

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