Lompat ke konten Lompat ke sidebar Lompat ke footer

Section 7 Quiz 2 - L4-L6

 


1. Which two statements are true?

(Pilih semua jawaban yang benar)

The purpose of a setter method is to allow private data to be modified safely (*)

The purpose of a getter method is to grant other classes access to public data.

The purpose of a setter method is to modify a public field

The purpose of a getter method is to return the value of a private field (*)

Correct

(1/1) Point

2. Setters are void return type methods.

benar (*)

Palsu

Correct

(1/1) Point

3. Access and visibility of a class should be limited as much as possible.

benar (*)

Palsu

Correct

(1/1) Point

4. An object reference directs you from one object to another.

benar (*)

Palsu

Correct

(1/1) Point

5. Which two statements are true about getter methods?

(Pilih semua jawaban yang benar)

You must have a setter method if you have a getter method.

Getters have a public access modifier. (*)

Getters usually accept no arguments. (*)

Getter methods typically return void.

Correct

6. Which two statements are true?

(Pilih semua jawaban yang benar)

An object can access another object’s public fields. (*)

An object can access another object’s main method.

An object can access another object’s public methods. (*)

An object can access another object’s public constructor.

Correct

(1/1) Point

7. Which two are access modifiers?

(Pilih semua jawaban yang benar)

static

public (*)

private (*)

final

Correct

(1/1) Point

8. Which statement is true?

A constructor can be written to accept arguments. (*)

The default constructor can accept arguments.

The default constructor is still available when you add your own constructor.

You must write at least one constructor in your class.

Correct

(1/1) Point

9. All overloaded methods share the same name.

benar (*)

Palsu

Correct

(1/1) Point

10. Method overloading can be a useful technique for defining methods with similar functionality or calculations.

benar (*)

Palsu

Correct

11. Methods can call other methods in the same class.

benar (*)

Palsu

Correct

(1/1) Point

12. 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 local variable.

A private variable.

A static variable. (*)

A public variable.

Correct

(1/1) Point

13. You never need to instantiate a Math object.

benar (*)

Palsu

Correct

(1/1) Point

14. 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;


   public static void display(){

     System.out.println(employeeID);

     System.out.println(name);

   }

}

Static variables are only accessible from instance methods.

Static variables cannot be referenced from methods.

The variable name has a null value.

It would be possible to call the display() method and attempt to reference an object’s name before any object exists. (*)

Correct

(1/1) Point

15. An object must be instantiated before its non-static fields and methods can be accessed.

benar (*)

Palsu

Correct

Posting Komentar untuk "Section 7 Quiz 2 - L4-L6"