• Tidak ada hasil yang ditemukan

Test: JFo Java Foundations Midterm Exam

N/A
N/A
Andika Fikri Azhari

Academic year: 2023

Membagikan "Test: JFo Java Foundations Midterm Exam"

Copied!
16
0
0

Teks penuh

(1)

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 2

(Answer all questions in this section)

1. Which of the following language is called a procedural language?

Java C++

C (*) Java C Correct (1/1) Points

2. In the code example below, identify any methods:

public class Employee { public String name = " Duke";

public int empId = 12105;

public float salary;

public void displaySalary(){

System.out.println("Employee Salary: "+salary);

} } salary empId name

displaySalary() (*) Correct

(1/1) Points

3. In object oriented programming, there is an emphasis on which of the following two:

(Choose all correct answers)

(2)

Modeling objects. (*) Creation of procedures.

Object interaction without a prescribed order. (*) Writing algorithms.

Correct (1/1) Points

4. You can set any number of breakpoints for your program.

True (*) False Correct (1/1) Points

5. When the program runs normally (when not in debug mode), which statement is true about breakpoints?

Breakpoints will stop program execution at the first breakpoint.

Breakpoints will not have any effect on program execution. (*) Breakpoints will stop program execution at the last breakpoint.

Any Breakpoint will stop program execution.

Correct (1/1) Points

Page 1 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 2

(Answer all questions in this section)

6. A breakpoint can be set by clicking a number in the left margin of the IDE.

Clicking again removes the breakpoint.

True (*) False Correct

(3)

(1/1) Points

7. What is the correct order of steps in the Spiral Model of Development?

Requirements, Design, Test, Develop Design, Requirements, Develop, Test Design, Develop , Requirements, Test Requirements, Design, Develop, Test (*) Correct

(1/1) Points

8. The Spiral Model reflects an iterative development process.

True (*) False Correct (1/1) Points

9. If the requirement step of the Spiral Model of development is forgotten, which of the following could occur?

Required software features are missing from the program. (*) The Program gives inaccurate results.

Solutions seem elusive.

Code becomes messy.

Correct (1/1) Points Section 3

(Answer all questions in this section)

10. Which keyword makes a variable’s value unchangeable?

const final (*) static break Correct (1/1) Points

Previous Page 2 of 10 Next

(4)

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3

(Answer all questions in this section)

11. How many bits are in a byte?

2 4 6 7 8 (*) Correct (1/1) Points

12. Assuming x is an int, which of the following are ways to increment the value of x by 1?

(Choose all correct answers)

x = x +1; (*) x = +1;

x+;

x++; (*) x += 1; (*) Correct (1/1) Points

13. Which is valid syntax to declare and initialize a String variable?

String x= "Java"; (*) String x = Java;

String "x" = Java;

String "x" = "Java";

Correct (1/1) Points

(5)

14. Identify the variable declared in the given code.

public class Welcome {

public static void main(String args[]) { int a = 2;

System.out.println("a is " + a);

} } int a (*) Welcome 2

Incorrect. Refer to Section 3 Lesson 1.

(0/1) Points

15. What is the output?

public class Welcome {

public static void main(String args[]) {

System.out.println("This is my first program");

int a = 2;

System.out.println("a is " + a);

} } a=2

This is my first program a is 2 (*) This is my first program a is + a This is my first program

Correct (1/1) Points

Previous Page 3 of 10 Next

Test: JFo Java Foundations Midterm Exam

(6)

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3

(Answer all questions in this section)

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

(Choose all correct answers)

Underscores help make large numbers more readable. (*) Underscores do not affect the value of the variable. (*) Underscores change the value of the number.

Underscores help the compiler interpret large numbers.

Correct (1/1) Points

17. Automatic promotion from smaller data type to a larger data type is not allowed in Java.

True False (*) Correct (1/1) Points

18. Which exception occurs because a String cannot be parsed as an int?

NumberFormatException (*) ArithmeticException

NullPointerException ValueNotFoundException Correct

(1/1) Points

19. What is the output?

public static void main(String args[]) { String greet1 = "Hello";

String greet2 = "World";

String message2 = greet1 +" " +greet2 +" " +2016 +"!";

(7)

System.out.println(message2);

}

"Hello World 2016"

"Hello" "World" "2016" "!"

Hello World 2016 ! (*) Hello World

Correct (1/1) Points

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

True (*) False Correct (1/1) Points

Previous Page 4 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 3

(Answer all questions in this section)

21. An Object cannot have String objects as properties.

True False (*) Correct (1/1) Points

22. Which two statements are true about the Scanner class?

(Choose all correct answers)

A Scanner object doesn’t have fields and methods.

A Scanner object opens a stream for collecting input. (*) A Scanner’s delimiter can be changed. (*)

Scanners cannot read text files.

(8)

Correct (1/1) Points

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

True (*) False Correct (1/1) Points

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

True (*) False Correct (1/1) Points Section 4

(Answer all questions in this section)

25. Which method returns the length of a String?

findLength () length() (*) compareTo() charAt() Correct (1/1) Points

Previous Page 5 of 10 Next

Test: JFo Java Foundations Midterm Exam

(9)

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

26. The indexOf() method returns the index value of a character in the string.

True (*) False Correct (1/1) Points

27. The replaceFirst() method replaces only the first occurrence of matching character pattern in a string.

True (*) False Correct (1/1) Points

28. What is the output?

public static void main(String args[]) { String alphaNumeric = "Java World!" + 8;

System.out.println(alphaNumeric);

}

Java World!8 (*) Java World! 8 Java World! + 8 Compilation error.

Correct (1/1) Points

29. Which is a risk of using fully qualified class names when importing?

Code readability is reduced. (*) Performance of the code is reduced.

Memory usage is increased.

The compiler runs longer.

(10)

Correct (1/1) Points

30. The import statement consists of two parts.

import package.className;

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

True (*) False Correct (1/1) Points

Previous Page 6 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

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

;

!

~

* (*) Correct (1/1) Points

32. Import statements are placed above the class definition.

True (*) False Correct (1/1) Points

(11)

33. Which class is used to generate random numbers?

Random (*) Number Integer Double Correct (1/1) Points

34. Using the Random class requires an import statement.

True (*) False Correct (1/1) Points

35. You need to generate random integer values between 0 and 80 (inclusive).

Which statement should you use?

nextInt(81); (*) nextInt(80);

nextInt();

nextInt(0-79);

Correct (1/1) Points

Previous Page 7 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

36. Which two are the features of the Math class?

(Choose all correct answers)

Math methods can be invoked with Strings as arguments.

Common math functions like square root are taken care of in the language. (*)

(12)

The Math methods can be invoked without creating an instance of a Math object. (*)

You don’t have to worry about the data type returned from a Math method.

Correct (1/1) Points

37. All the methods in the Math class are static methods.

True (*) False Correct (1/1) Points

38. 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(3.5, 10);

testInstance.testMethod(10, 3.5, 0);

testInstance.testMethod(3.5);

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

Correct (1/1) Points

39. Which of the following two operations are appropriate for the main method?

(Choose all correct answers)

Creating instances of objects (*) Assigning memory to the variables

Calling an instance object’s field and methods. (*) Calling local variables declared within a class’s method Correct

(1/1) Points

40. void type methods don’t return any values

(13)

True (*) False Correct (1/1) Points

Previous Page 8 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 4

(Answer all questions in this section)

41. Methods allow all instance of a class to share same behaviors.

True (*) False Correct (1/1) Points Section 5

(Answer all questions in this section)

42. A customer is eligible for a discount based on certain criteria. Under what conditions does "You qualify for a discount" print? (Hint: There may be more than one correct answer)

int purchase;

int rewardPoints;

if (purchase >= 2000 || rewardPoints >= 4000) { System.out.println("You qualify for discount");

}

(Choose all correct answers)

When rewardPoints is more than 2000 or purchase greater than 1000 When purchase is 2000 regardless of the value of rewardPoints (*) When purchase is 4000 and rewardPoints is 2000 (*)

When rewardPoints is more than 1000 and purchase is 1000

(14)

Correct (1/1) Points

43. In a boolean expression which uses the && operator, what would make this expression evaluate to true?

boolean x = (firstCondition && secondCondition);

If the first condition is false, but the second condition is true If both the first condition and second condition are false If the first condition is true, but the second condition is false If both the first condition and second condition are true (*) Correct

(1/1) Points

44. In the OR (||) test, if the first expression on the left hand side is true then there is no need to evaluate the second statement.

True (*) False Correct (1/1) Points

45. What is the output?

public static void main(String args[]) { char ch ='c';

switch(ch) { case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

System.out.println("Vowels");

break;

default:

System.out.println("Consonants");

} }

Vowels

(15)

Vowels

Consonants (*) Compilation error Correct

(1/1) Points

Previous Page 9 of 10 Next

Test: JFo Java Foundations Midterm Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5

(Answer all questions in this section)

46. A break statement causes control to transfer to the end of the switch statement.

True (*) False Correct (1/1) Points

47. What are the possible values of a boolean data type in Java?

good/bad yes/no true/false (*) 0/1

Correct (1/1) Points

48. A String comparison with == compares the Strings’ locations in memory and not the content of the String.

True (*) False Correct (1/1) Points

(16)

49. Which operator is used to test if both sides of a boolean expression are equal?

>=

== (*)

<=

=

Correct (1/1) Points

50. How should Strings be compared?

==

The equals() method (*)

~=

=

Correct (1/1) Points

Previous Page 10 of 10

Referensi

Dokumen terkait