Strings
Primitives and Order of Operations
Casting
Objects
Other
100

What gets printed from the following code?

System.out.println("**");
System.out.print("*");

System.out.print("*");

**
**

100

Write the code statement for a new variable named alex with a value of 12.

int alex = 12;

double alex = 12.0;

100

What is casting?

Turn one primitive type into a different primitive type (usually with numbers)

100

What Java keyword is used when instantiating an object?

new

100

What is the return type of the following method?

public double myMethod(int a, boolean b) 

double

200

What gets printed from the following code?

String str = "basic vs c++";
System.out.println(str.substring(2));

sic vs c++

200

(9 + 10) % 12

7

200

Write the code statement to turn the following code into an int.

double dub = 22.0;

(int) dub
int x = (int) dub;

200

Write the code for a constructor for the class named Person.

public Person() {}

public Person(String name) { ... }

200

True/False: Objects and primitives both store and pass values when used

False, Objects store addresses

300

What is the value of str after the code executes?

String str = "Hello World"
str.substring(0, 5);

"Hello World"

300

Name 4 different primitive types

int, double, boolean, char, byte, long, short, float

300

What is the value of d after the code executes?

double d = 5.0;
d += (double) (7 / 2);

8.0

300

A Class is a template for an object. Explain what each of the following are relative to classes: instance variables, attributes, constructor, methods.

Instance variables: data stored
Attributes: other term for instance variables
Constructor: used to create instances of the class
Methods: behavior of the object

300

public WindTurbine(double e) { 

efficiencyRating = e; }

Write the code statement to instantiate a WindTurbine object wt that has an efficiency of 0.75.

WindTurbine wt = new WindTurbine(0.75);

400

What is the value of str after the code executes?

String str = "my store";
str += str.substring(0, 3);

"my storemy"

400

The following code is used to perform some sort of arithmetic function. Give this function an appropriate name for what it does.

int _____ (int x) { return x % 100 / 10; }

getTensDigit() or something similar

400

System.out.println((char)('A' + 7));

'H'

400

What is method overloading and when can it NOT happen?

Same method name, different parameters. When two methods with the same name and parameter types exist in the same class.

400

When calling a method with formal parameters, the actual parameters passed must have _____ types.

matching, the same, etc

500

What gets printed from the following code?

String str = "basic vs c++";
System.out.println(str.indexOf("basic") + 0 + str.substring(5, 9) + str.indexOf("basic") + 1);

0 vs 01

500

What gets printed from the following code?

System.out.println(5 + 4 / (16 % 4));

ArithmeticException, divide by 0

500

What is the value of i after the code executes?

final int i = (int) 10.0;
i = (int) ((double) 5 / 2);

Compile error. Cannot reassign the value of a final variable.
500

An Object's toString() method can be overridden to print more user friendly and useful text. What is the default functionality of the toString() method?

returns the Object's reference/address as a String
500

What gets printed from the following code?

System.out.println(0 + "0" + 1 + 2);

0012