Professional Documents
Culture Documents
PDF Section 7 Quiz 1 Dan 2 DD
PDF Section 7 Quiz 1 Dan 2 DD
1. When you write your own constructor, the default constructor is no longer available.
True (*)
False
2. You create an Employee object with a String employeeName field. What is the default value for
employeeName?
null (*)
A space
“Name”
“default”
3. In Java, the this keyword can be used to reference the current object’s fields and methods.
True (*)
False
5. How would you instantiate the Employee class from a main method located in another class?
String s1 = "Hello";
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);
s1: Welcome!
s2: Welcome! (*)
s1: Hello
s2: Welcome!
s1: Hello
s2: Hello
s1: Welcome!
s2: Hello
String
Student (*)
null
Class
11. Which two statements are true about objects of the same class? (Choose all correct answers)
Each object will have the same reference variable to the location in memory.
Each new instance of an object will have a different location in memory. (*)
All objects of the same class have the same methods. (*)
All objects are equal.
12. In the following statements, how many employee objects are created?
Employee e1 = new Employee();
Employee e2 = new Employee();
Employee e3 = new Employee();
0
1
3 (*)
2
13. How can you retrieve a value from a method?
Pass a variable as an argument to the method.
Define a variable as a field member of the method
Use a return statement and define the method’s return type as non-void (*)
Define the method return type as void
15. First, you decide the radius of each circle in the logo. Then using the same radius you draw 5 circles of same size.
All these circles will have properties like radius and color. All circles share behaviors to calculate circumference
and area. Can you identify which of the following is an object?
circle (*)
circumference
fiveCircles
radius
s1: Hello
s2: Welcome!
s1: Hello
s2: Hello
s1: Welcome!
s2: Welcome! (*)
s1: Welcome!
s2: Hello
19. Which two statements are true about objects of the same class? (Choose all correct answers)
24. In Java, the this keyword can be used to reference the current object’s fields and methods.
True (*)
False
25. How could you write the Employee constructor so that its parameters are named the same as the fields they’re
initializing?
public class Employee{
private String name;
private double salary;
public Employee(String name, double salary){
//initialize name
//initialize salary
}
}
28. You create an Employee object with a String employeeName field. What is the default value for
employeeName?
null (*)
A space
“Name”
“default”
29. Which two statements are NOT true about constructors? (Choose all correct answers)
2. Method overloading can be a useful technique for defining methods with similar functionality or calculations.
True (*)
False
3. How would you complete this code so that one add method calls the other add method?
6. To make fields directly accessible to other classes, the class fields must be marked public.
True (*)
False
9. Which two statements are true about getter methods? (Choose all correct answers)
You must have a setter method if you have a getter method.
Getters usually accept no arguments. (*)
Getters have a public access modifier. (*)
Getter methods typically return void.
12. Given the following code, why does your IDE complain that “non-static variable name cannot be referenced
from a static context”?
public class Employee{
public static int employeeID;
public String name;
13. If you need to make a particular variable belong to a class rather than any individual instance, what type of
variable should you use?
A static variable. (*)
A local variable.
A public variable.
A private variable.
14. Static variables of a class can be accessed, even if the class has not been instantiated.
True (*)
False
18. Method overloading can be a useful technique for defining methods with similar functionality or calculations.
True (*)
False
19. An object must be instantiated before its non-static fields and methods can be accessed.
True (*)
False
20. The fields and methods of the Math class cannot be directly accessed as they are static.
True
False (*)
Correct Correct
7. Static variables of a class can be accessed, even if the class has not been instantiated. Mark
for Review
(1) Points
True (*)
False
Correct Correct
8. If you need to make a particular variable belong to a class rather than any individual instance,
what type of variable should you use? Mark for Review
(1) Points
A local variable.
A public variable.
A private variable.
Correct Correct
10. Which two statements are true about getter methods? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. Which two statements are true about private access modifier? Mark for Review
(1) Points
final
private (*)
public (*)
static
Correct Correct
The purpose of a getter method is to grant other classes access to public data.
The purpose of a getter method is to return the value of a private field (*)
The purpose of a setter method is to allow private data to be modified safely (*)
Correct Correct
16. You never need to instantiate a Math object. Mark for Review
(1) Points
True (*)
False
17. If you need to make a particular variable belong to a class rather than any individual instance, what type of variable
should you use? Mark for Review
(1) Points
A private variable.
A public variable.
A local variable.
18. Static variables of a class can be accessed, even if the class has not been instantiated. Mark for Review
(1) Points
True (*)
False
19. Setters are void return type methods. Mark for Review
(1) Points
True (*)
False
20. Which three can vary in overloaded methods? Mark for Review
(1) Points
21. You can write more than one constructor in a class. Mark for Review
(1) Points
True (*)
False
Correct Correct
22. Method overloading can be a useful technique for defining methods with similar functionality or calculations.
Mark for Review
(1) Points
True (*)
False