Unit 5: Writing Classes

Showing 17 of 17 questions

Q1
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q2
MULTIPLE_CHOICEHard

What is the output of the following code?

Q3
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q4
MULTIPLE_CHOICEHard

What is the output of the following code?

Q5
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q6
MULTIPLE_CHOICEHard

What is the output of the following code?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEMedium

A static method:

Q9
MULTIPLE_CHOICEMedium

In a Java class, the keyword "this" refers to:

Q10
MULTIPLE_CHOICEMedium

Method overloading occurs when:

Q11
MULTIPLE_CHOICEMedium

A variable declared inside a for loop:

Q12
MULTIPLE_CHOICEMedium

When System.out.println(myObject) is called, Java automatically invokes:

Q13
MULTIPLE_CHOICEMedium

A static variable in Java:

Q14
MULTIPLE_CHOICEMedium

Consider the following class. \npublic class Counter { private int count; private int limit; public Counter(int limit) { this.limit = limit; count = 0; } public void increment() { if (count < limit) count++; } public int getCount() { return count; } } \nWhat is the output after the following code executes? \nCounter c = new Counter(3);\nfor (int i = 0; i < 5; i++) { c.increment(); }\nSystem.out.println(c.getCount());

Q15
MULTIPLE_CHOICEHard

A class Student has private instance variables String name and double gpa. The equals method is written as: \npublic boolean equals(Object obj) { Student other = (Student) obj; return name.equals(other.name) && gpa == other.gpa; } \nWhich of the following could cause this method to throw an exception at runtime?

Q16
MULTIPLE_CHOICEHard

Consider the following class: public class Counter { private static int count = 0; private int id; public Counter() { count++; id = count; } public static int getCount() { return count; } public int getId() { return id; } } After executing: Counter a = new Counter(); Counter b = new Counter(); Counter c = new Counter(); What are the values of a.getId(), c.getId(), and Counter.getCount()?

Q17
MULTIPLE_CHOICEMedium

What is the output? public class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public void translate(int dx, int dy) { x += dx; y += dy; } public String toString() { return "(" + x + "," + y + ")"; } } Point p = new Point(3, 4); Point q = p; q.translate(1, 1); System.out.println(p);

Advertisement