0% found this document useful (0 votes)
260 views

Quiz7 1

The document contains a 15 question quiz about object-oriented programming concepts in Java. Some key points covered are: - When you write your own constructor, the default constructor is no longer available. - Objects are accessed using reference variables. - Each new instance of an object will have a different location in memory.

Uploaded by

rizqi joeni
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
260 views

Quiz7 1

The document contains a 15 question quiz about object-oriented programming concepts in Java. Some key points covered are: - When you write your own constructor, the default constructor is no longer available. - Objects are accessed using reference variables. - Each new instance of an object will have a different location in memory.

Uploaded by

rizqi joeni
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

Section 7 Quiz 1 - L1-L3

(Answer all questions in this section)

1. When you write your own constructor, the default constructor is


no longer available. Mark for Review
(1) Points

True (*)

False

Correct Correct

2. You create an Employee object with a String employeeName field.


What is the default value for employeeName? Mark for Review
(1) Points

null (*)

A space

�Name�

�default�

Correct Correct

3. In Java, the this keyword can be used to reference the current


object�s fields and methods. Mark for Review
(1) Points

True (*)

False

Correct Correct

4. Which statement is true about the default constructor of a class?


Mark for Review
(1) Points
Java automatically provides a constructor for every class. (*)

You must write a default constructor.

The default constructor always returns void.

Default constructor should have at least one argument.

Correct Correct

5. How would you instantiate the Employee class from a main method
located in another class?

public class Employee{


private String name;
private double salary;

public Employee(String n, double s){


name = n;
salary = s;
}
} Mark for Review
(1) Points

Employee emp1 = new Employee();

Employee emp1 = new Employee(50000);

Employee emp1 = new Employee(50000, "Syam");

Employee emp1 = new Employee("Syam", 50000); (*)

Correct Correct
6. An object reference with a null value points to an empty location in memory.
Mark for Review
(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 7 Lesson 3.


7. Objects are accessed using reference variables. Mark for Review
(1) Points

True (*)

False

Correct Correct

8. What is the output of the following code?

String s1 = "Hello";
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2); Mark for Review
(1) Points

s1: Welcome!
s2: Welcome! (*)

s1: Hello
s2: Welcome!

s1: Hello
s2: Hello

s1: Welcome!
s2: Hello

Correct Correct

9. Java developers don't need to know an object�s location in


memory. Mark for Review
(1) Points

True (*)

False

Correct Correct
10. In this statement, identify the type of the variable s.

Student s = new Student(); Mark for Review


(1) Points

String

Student (*)

null

Class

Correct Correct
11. Which two statements are true about objects of the same class? Mark for
Review
(1) Points

(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.

Incorrect Incorrect. Refer to Section 7 Lesson 2.

12. In the following statements, how many employee objects are


created?

Employee e1 = new Employee();


Employee e2 = new Employee();
Employee e3 = new Employee();
Mark for Review
(1) Points

1
3 (*)

Correct Correct

13. How can you retrieve a value from a method? Mark for Review
(1) Points

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

Correct Correct

14. Class name should follow Camel casing rules. Mark for Review
(1) Points

True (*)

False

Correct Correct

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?
Mark for Review
(1) Points

circle (*)

circumference
fiveCircles

radius

Incorrect Incorrect. Refer to Section 7 Lesson 1

You might also like