Variables Flashcards

1
Q

1) Class Variables (static fields)

A class variable is any field declared with the s______ modifier; this tells the compiler that there is exactly one copy of this variable in existence.

If you change the value of a class variable in one object, it will change it in all objects!

e.g. static int age = 10;

A

static

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

2) Instance Variables (non-static fields)

Non-static fields are also known as instance variables because their values are u________ to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.

e.g. int age;

A

unique

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

3) Local Variables

A local variable is a varible which is declared between the opening and closing b_______ of a m__________.
As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

e.g. public carSpeed( ) {
int maxSpeed = 100;
}

A

braces of a method

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

4) Parameters

Method Parameters are very useful as they are variables that we can pass into our method.

e.g.

printInfo(“Tom”, 24); //Here, we are calling a method and passing the arguments Tom and 24 into the method’s
parameters

public static void printInfo(String name, int age) { //The parameters that this method has set
System.out.println(name + “is “ + age + “ years old.”); are String name and int age
}

A

fields

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