Method Signatures
Class vs Instance
Objects and References
Math and String class
100

What is the return type in: public int add(int x, int y);

Int

100

Which type of method requires the creation of an object?

Instance

100

Strings are an example of a _________

Object

Reference Data Type

100

What does Math.random() return 

A random double from 0.0 to 1.0

200

True or False: Two methods can have the same name if the parameters differ

True

200

Why can you call Math.sqrt() without creating a Math object?

Because sqrt() is a static method

200
True or False: Objects are primitive data types

False

200

Explain what "abc".indexOf("b") returns and why.

1

Index starts at 0

300

Write a valid method signature named combine that takes two Strings and returns a String.

public String combine(String a, String b).

300

Write one line of code calling an instance method from an object named piano.

piano.playNote() 

300

If Person a = new Person(); 

Person b = a;

How many Person objects exist?

One

Only one "Person" is created.

Person b is assigned a reference to a

300

What does s.substring(1, 4) return if s = "hello"?

"ell"

400

What is the role of the Constructor?

To initialize the instance variables of a class

400

True or False: Static methods can use instance variables directly.

False.

Static methods belong to a class, not a specific object. If there is no object, then there is no reference to the instance variables. That is why you must give static methods parameters that you may not need to do for instance methods. 

400

Car c;

c.start();

What does Null mean here?

c does not reference any object.

Calling an instance method on Null returns an error.

400

Why does Math.abs(-5.0) return a double but Math.abs(-5) returns an int?

Overloaded Method

500

When you define your own version of toString(), you are ___________ the one in the Object class.

Using a method defined from a superclass is known as ______________.

Overriding

Inheritance

500

Why must you construct an object before calling its instance methods?

Instance methods rely on object state, which doesn't exist without an object.

500

Why does == fail for string comparison?

It compares references, not text.