Lompat ke konten Lompat ke sidebar Lompat ke footer

Section 4 Quiz 1 - L1-L2

1. Which of the following wild card character is used to import all the classes in a particular package?

* (*)

!

~

;

Correct

(1/1) Point

2. The classes of the Java class library are organized into packages.

benar (*)

Palsu

Correct

(1/1) Point

3. Which two are valid import statements of the Scanner class?

(Pilih semua jawaban yang benar)

import java.util.*; (*)

import java.util.Scanner; (*)

import java.util;

import java.*;

Correct

(1/1) Point

4. Given the import statement:

import java.awt.font.TextLayout;

which is the package name?

java

java.awt.font (*)

java.awt

awt.font

Incorrect. Refer to Section 4 Lesson 2.

(0/1) Point

5. Import statements are placed above the class definition.

benar (*)

Palsu

Correct

6. Which package is implicitly imported?

java.io

ava.awt

java.math

java.lang (*)

Correct

(1/1) Point

7. The import statement consists of two parts.


import package.className;


One is the package name and the other is the classname.

benar (*)

Palsu

Correct

(1/1) Point

8. Which of the following are the arguments in the following method?


Employee emp = new Employee();

emp.calculateSalary(100000, 3.2, 15);

calculateSalary(100000, 3.2, 15);

emp.calculateSalary(100000, 3.2, 15);

100000, 3.2, 15 (*)

emp

Correct

(1/1) Point

9. An argument is a value that's passed during a method call

benar (*)

Palsu

Correct

(1/1) Point

10. In Java, methods usually hold the properties of an object.

benar

Palsu (*)

Correct

11. How many arguments does the following method accept?


public void simpleInterest(double principal, int noofYears, double interestRate){

  System.out.println("The interest rate is " +interestRate );

}

0

3 (*)

2

1

Correct

(1/1) Point

12. Which is a valid way of calling the testMethod in the TestClass? Assume a testInstance has been created.


public void testMethod(int x, double y){

   System.out.println(x/y);

}

testInstance.testMethod(10, 3.5, 0);

testInstance.testMethod(3.5, 10);

testInstance.testMethod(10, 3.5); (*)

testInstance.testMethod(3.5);

testInstance.testMethod(10);

Correct

(1/1) Point

13. Object instantiation is done using what keyword?

void

new (*)

instance

System

Correct

(1/1) Point

14. Which of the following scenarios would be ideal for writing a method?

When you don’t want to repeat similar lines of code to describe an object’s behavior. (*)

When you don’t find similar lines of code to describe an object’s behavior.

To group similar data types together

For every five to six lines of code.

Correct

(1/1) Point

15. Which of the following statements are true?

(Pilih semua jawaban yang benar)

Methods can never be written with more than four parameters.

Methods cannot be written with parameters.

Methods can be written with any number of parameters. (*)

Parameter values can never be used within the method code block.

Parameter values can be used within the method code block. (*)

Correct

PERCOBAAN KE 2 QUIZ

 1. A character preceded by backslash is called an escape sequence.

benar (*)

Palsu

Correct

(1/1) Point

2. Given the expression:


String message = "Hello World";


Which is the String Literal?

String message = "Hello World";

message

String message

Hello World (*)

Correct

(1/1) Point

3. Which two statements compile?

(Pilih semua jawaban yang benar)

String size = ‘M’;

char size = ”m”;

String size = “M”; (*)

char size = ’m’; (*)

Correct

(1/1) Point

4. The print() method prints to the console and automatically creates a line.

benar

Palsu (*)

Incorrect. Refer to Section 3 Lesson 3.

(0/1) Point

5. A String can be created by combining multiple String Literals.

benar (*)

Palsu

Correct

6. An Object cannot have String objects as properties.

benar

Palsu (*)

Correct

(1/1) Point

7. System.in readies Scanner to collect input from the console.

benar (*)

Palsu

Correct

(1/1) Point

8. The Scanner class accepts input in which form?

Future

Integer

Tokens (*)

Callables

Correct

(1/1) Point

9. These two code fragments perform the same task.


// Fragment 1

String inputString = JOptionPane.showInputDialog("??");

int input = Integer.parseInt(inputString);

input++;


// Fragment 2

int input = Integer.parseInt(JOptionPane.showInputDialog("??")) + 1;

benar (*)

Palsu

Correct

(1/1) Point

10. A double with the value of 20.5 is cast to an int. What is the value of the int?

21

25

20.5

20 (*)

Incorrect. Refer to Section 3 Lesson 4.

11. The Java compiler automatically promotes byte, short, and chars data type values to int data type.

benar (*)

Palsu

Correct

(1/1) Point

12. Which two statements are correct about the usage of an underscore?

(Pilih semua jawaban yang benar)

Underscores change the value of the number.

Underscores help make large numbers more readable. (*)

Underscores do not affect the value of the variable. (*)

Underscores help the compiler interpret large numbers.

Correct

(1/1) Point

13. Which two statements are true about type casting?

(Pilih semua jawaban yang benar)

Type casting retains the size of the value or the original data type.

Type casting changes the type of the value stored. (*)

Type casting cannot be performed on equations.

Type casting lowers the range of possible values. (*)

Correct

(1/1) Point

14. Which is a valid way to parse a String as an int?

nt intVar1 = (int)"100";

int intVar1 = Integer.parseInt("One Hundred");

int intVar1 = Integer.parseInt("100"); (*)

int intVar1 = "100";

Correct

(1/1) Point

15. What is parsing?

Converting numeric data to text

Converting numeric data to a specified numeric data type

Reading text from numeric data

Converting text to numeric data (*)

Correct

Posting Komentar untuk "Section 4 Quiz 1 - L1-L2"