Beruflich Dokumente
Kultur Dokumente
double d = 5.0;
int i[] = {1,2,3,4};
List l = new List();
Double k = new Double();
Tree t;
float f;
Computer c = null;
Q3. In this question, I show you the signatures of some constructors and methods that could be
defined for a Bank class, a class intended to store information about a bank. I would like you to show
me how you would call the methods. If the method or constructor returns a value, I would like you to
put the call on the right hand side of an assignment statement so that the returned result is saved in a
variable. For the purposes of this question, you can assume that the following variables have been
declared and initialized, if necessary:
Bank bank;
String bankName;
String bankAddress;
int id;
Person accountOwner;
1
Advanced Programming Lecture Quiz 1 – 2/11/2017
String ownerName;
Account[ ] accountList;
Do not provide an implementation for these methods.
a. public Bank (String name)
b. public String getAddress()
c. public void printAccountsList()
d. public void setClient (Person owner, int accountID)
e. public Account[] getAccounts ()
Q4. For each term in the left column, write the letter for the description from the right column that
best matches the term.
Q5. MCQ
1. Consider the following code fragment
Rectangle r1 = new Rectangle();
r1.setColor(Color.blue);
Rectangle r2 = r1;
r2.setColor(Color.red);
After the above piece of code is executed, what are the colors of r1 and r2 (in this order)?
(a) Color.blue
Color.red
(b) Color.blue
Color.blue
(c) Color.red
Color.red
2
Advanced Programming Lecture Quiz 1 – 2/11/2017
(d) Color.red
Color.blue
(e) None of the above.
2. A constructor
(a) Must have the same name as the class it is declared within.
(b) Is used to create objects.
(c) May be declared private
(d) Both (a) and (b) above
(e) (a), (b) and (c) above.
3. You read the following statement in a Java program that compiles and executes.
submarine.dive(depth);
What can you say for sure?
(a) depth must be an int
(b) dive must be a method.
(c) dive must be the name of an instance field.
(d) submarine must be the name of a class
(e) submarine must be a method.
4. Consider,
public class MyClass
{
public MyClass(){/*code*/}
// more code...
}
To instantiate MyClass, you would write?
3
Advanced Programming Lecture Quiz 1 – 2/11/2017