What is the return type in: public int add(int x, int y);
Int
Which type of method requires the creation of an object?
Instance
Strings are an example of a _________
Object
Reference Data Type
What does Math.random() return
A random double from 0.0 to 1.0
True or False: Two methods can have the same name if the parameters differ
True
Why can you call Math.sqrt() without creating a Math object?
Because sqrt() is a static method
False
Explain what "abc".indexOf("b") returns and why.
1
Index starts at 0
Write a valid method signature named combine that takes two Strings and returns a String.
public String combine(String a, String b).
Write one line of code calling an instance method from an object named piano.
piano.playNote()
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
What does s.substring(1, 4) return if s = "hello"?
"ell"
What is the role of the Constructor?
To initialize the instance variables of a class
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.
Car c;
c.start();
What does Null mean here?
Calling an instance method on Null returns an error.
Why does Math.abs(-5.0) return a double but Math.abs(-5) returns an int?
Overloaded Method
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
Why must you construct an object before calling its instance methods?
Instance methods rely on object state, which doesn't exist without an object.
Why does == fail for string comparison?
It compares references, not text.