Sunteți pe pagina 1din 47

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

o Design, Develop , Requirements, Test


o Requirements, Design, Test, Develop
o Requirements, Design, Develop, Test (*)
o Design, Requirements, Develop, Test
2. If the requirement step of the Spiral Model of development is forgotten, which of the
following could occur?
o Code becomes messy.
o Required software features are missing from the program. (*)
o Solutions seem elusive.
o The Program gives inaccurate results.
3. Which of the following are adequate definitions for components of the Spiral Model of
Development? Mark for Review
o Requirements: Start the development
o Test: Run the code and verify results (*)
o Develop: Collect all specified instructions
o Design: Plan the approach (*)
4. The Spiral Model reflects an iterative development process.
o True (*)
o False
5. Which of the following language is called a procedural language?
o Java C
o C++
o Java
o C (*)
6. In object oriented programming, an object comprises of properties and behaviors
where properties represented as fields of the object and behavior is represented as
method. Mark for Review
o True (*)
o False
7. 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(){
out.println(“Employee Salary: “+salary);
}
}
o Name
o Salary
o empId
o displaySalary() (*)
8. An object may interact with another object by invoking methods.
o True (*)
o False
9. You have a beautiful garden at home. On Sunday, you start budding your rose plant
to make few more samples of rose plants to plant in the garden. Can you categorize
how this scenario could be represented by classes and instances?
o Samples are the class and the rose plant is the instances of samples.
o Rose plant is the class and the samples generated from the rose plant
are instances of that class. (*)
o Rose plant is the object and samples are not instances of the
https://www.coursehero.com/assets/img/qa/icon_A+.svgplant because they
have not grown yet.
o Samples of the rose plant are called classes and not the actual rose plant.
10. Java mostly reads code line-by-line.
o True (*)
o False
11. What is the purpose of adding comments in the code?
o Provide good look and feel of the code.
o It increases the execution time of the code.
o Provide an explanation about the code to the programmer. (*)
o To provide better security to the program.
12. Code within curly braces is called a “Block of code”. Mark for Review
o True (*)
o False
13. You can set any number of breakpoints for your program.
o True (*)
o False
14. Which of the following are considered Whitespace.
o Space between the [ ] braces.
o Blank lines in the code. (*)
o Space between words. (*)
o Space in the print statements.
o Indentation before the code. (*)
15. Which of the following 2 statements are true about whitespace? Mark for Review
o Whitespace reduces the performance of the program.
o Whitespace increases execution time of your program.
o Whitespace eliminates typing mistakes while programming.
o Whitespace helps to keep your code organized. (*)
o Whitespace makes your code more readable. (*)
 
1. In object oriented programming, there is an emphasis on which of the following two:
o Creation of procedures.
o Modeling objects. (*)
o Object interaction without a prescribed order. (*)
o Writing algorithms.
2. An object may interact with another object by invoking methods.
o True (*)
o False
3. In object oriented programming, an object comprises of properties and behaviors
where properties represented as fields of the object and behavior is represented as
method.
o True (*)
o False
4. A software feature may allow the user to perform a specific task.
o True (*)
o False
5. During the Design phase of software development, the programmer implements
features gathered during the Requirement phase.
o True
o False (*)
6. During the Testing phase of software development, which of the following are the
tasks undertaken by the programmer? Listing required features.
o Finding the bugs. (*)
o Fixing the bugs. (*)
o Planning the order to implement features.
7. A Java program can be written in the single line.
o True (*)
o False
8. Which two are the correct syntax for adding comments? (Choose all correct answers)
o Start with two slashes (//). End when the line ends. (*)
o Start with two slashes (//). End with two slashes (//).
o Start with a slash- star (/*). End with slash-star (/*).
o Start with two slashes and a star (//*). End with a star-slash (*/).
o Start with a slash-star (/*). End with a star-slash (*/). (*)
9. Code within curly braces is called a “Block of code”.
o True (*)
o False
10. char is the primitive textual data type in Java
o True (*)
o False
11. Which two statements compile? (Choose all correct answers)
o String name = “Java”; (*)
o String name = new String ( ‘Java’);
o String name = “J”; (*)
o String name = ‘Java’;
12. Which is the correct declaration for a char data type?
o char size = “Medium”;
o char size = ’Medium’;
o char size = “M”;
o char size = ’M’; (*)
13. What is the output?
public class Welcome {
public static void main(String args[]) {
out.println(“This is my first program”);
int a = 2;
System.out.println(“a is” + a);
}
}
o This is my first program a is + a
o a=2
o This is my first program a is 2 (*)
o This is my first program
14. Which two data types are appropriate for their variable?
o String firstName = “Alex”; (*)
o int averageDollarAmount = 19.95;
o boolean age = 20;
o double checkingAmount = 1500; (*)
15. Which two are valid? (Choose all correct answers)
o double doubleVar1, doubleVar2 = 3.1; (*)
o double doubleVar1, double doubleVar2 = 3.1;
o double doubleVar1; doubleVar2 = 3.1.
o double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)
16. Which two statements are true about type casting? (Choose all correct answers)
o Type casting cannot be performed on equations.
o Type casting retains the size of the value or the original data type.
o Type casting changes the type of the value stored. (*)
o Type casting lowers the range of possible values. (*)
17. Which is a valid way to parse a String as an int?
o int intVar1 = Integer.parseInt(“100”); (*)
o nt intVar1 = (int)”100″;
o int intVar1 = Integer.parseInt(“One Hundred”);
o int intVar1 = “100”;
18. Which exception occurs because a String cannot be parsed as an int?
o NumberFormatException (*)
o ArithmeticException
o NullPointerException
o ValueNotFoundException
19. in readies Scanner to collect input from the console.
o True (*)
o False
20. The Scanner class accepts input in which form?
o Integer
o Callables
o Tokens (*)
o Future
21. 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;
o True (*)
o False
22. What is the output?
public class Person {
public static void main(String args[]) {
int age = 20;
out.println(“Value of age: ” +age);
age = 5 + 3;
System.out.println(“Value of age: ” +age);
age = age + 1;
age++;
System.out.println(“Value of age: ” +age);
}
}
o Value of age: 20
Value of age: 8
Value of age: 10 (*)
o Value of age: 20
Value of age: 28
Value of age: 38
o Value of age: 20
Value of age: 208
Value of age: 20810
o Value of age: 20
Value of age: 8
Value of age: 9
23. What is the range of the byte data type?
o –27 to 27–1 (*)
o –215 to 215–1
o –231 to 231–1
o –263 to 263–1
24. This declaration represents a long data type.
long a = 123L;
o True (*)
o False
25. What is the output?
public static void main(String args[]) {
String greeting = “Java World!”;
String w = greeting.replace(“a”, “A”);
out.println(w);
}
o JavA World!
o World!
o JAva World!
o JAvA World! (*)
26. The indexOf() method returns the index value of a character in the string.
o True (*)
o False
27. The String class must be imported using java.lang.String;
o True
o False (*)
28. The String concat() method concatenates only String data types.
o True (*)
o False
29. The import statement consists of two parts.
import package.className;
One is the package name and the other is the classname.
o True (*)
o False
30. Which of the following wild card character is used to import all the classes in a
particular package?
o ~
o !
o ;
o * (*)
31. Import statements are placed above the class definition.
o True (*)
o False
32. Given the import statement:
import java.awt.font.TextLayout;
which is the package name?
o font
o awt.font (*)
o awt
o java
33. The Math class methods can be called without creating an instance of a Math object.
o True (*)
o False
34. What is the package name which contains Math class?
o net
o lang (*)
o awt
o io
35. Methods allow all instance of a class to share same behaviors.
o True (*)
o False
36. An argument is a value that’s passed during a method call
o True (*)
o False
37. Which of the following are the arguments in the following method?
Employee emp = new Employee();
calculateSalary(100000, 3.2, 15);
o calculateSalary(100000, 3.2, 15);
o calculateSalary(100000, 3.2, 15);
o 100000, 3.2, 15 (*)
o emp
38. How many arguments does the following method accept?
public void simpleInterest(double principal, int noofYears, double interestRate){
out.println(“The interest rate is ” +interestRate );
}
o 1
o 2
o 0
o 3 (*)
39. Which class is used to generate random numbers?
o Double
o Random (*)
o Integer
o Number
40. You need to generate random integer values between 0 and 80 (inclusive). Which
statement should you use?
o nextInt(0-79);
o nextInt(80);
o nextInt();
o nextInt(81); (*)
41. You need to generate random integer values in the range 2 through 10. This code
fragment will produce the desired result.
Random r = new Random();
nextInt(9) + 2; Mark for Review
o True (*)
o False
42. In the AND (&&) test, if the first expression on the left hand side is false, then there is
no need to evaluate the second statement.
o True (*)
o False
43. In Java, an if statement can be nested inside another if statement.
o True (*)
o False
44. An employee is eligible for a bonus based on certain criteria.
Under what conditions does “Eligible for a bonus” print?
int rating;
int experience;
if (rating > 1 && experience == 5) {
out.println (“Eligible for a bonus”);
}
o Less than 5 experience and 1 rating.
o 5 experience and 1 rating
o 5 experience and 2 or more rating (*)
o 5 rating and 1 experience
45. The equal sign (=) is used to make an assignment, whereas the == sign merely
makes a comparison and returns a boolean.
o True (*)
o False
46. A String comparison with == compares the Strings’ locations in memory and not the
content of the String.
o True (*)
o False
47. What is the output?
public static void main(String[] args) {
int age = 43;
if (age == 43){
out.print(“Bob is 43 “);
}
if (age == 50){
System.out.print(“Bob is 50 “);
}
}
o Bob is 43 Bob is 50
o Bob is 50
o No output
o Bob is 43 (*)
48. Which are used in a boolean expression? (Choose all correct answers)
o Variables (*)
o Loops
o Operators (*)
o Errors
49. A break statement causes control to transfer to the end of the switch statement.
o True (*)
o False
50. Which two of the following data types can be used in a switch statement? (Choose all
correct answers)
o boolean
o String (*)
o float
o int (*)

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


True (*)
False
Correct

2. A Java program can be written in the single line.


True (*)
False
Incorrect. Refer to Section 2 Lesson 2.

3. A breakpoint can be set by clicking a number in the left margin of the IDE. Clicking again
removes the breakpoint.
True (*)
False
Correct

4. Which of the following are considered Whitespace?


Space in the print statements.
Space between words.(*)
Space between the [ ] braces.
Blank lines in the code.(*)
Indentation before the code.(*)
Correct

5. Which two are the correct syntax for adding comments?


Start with a slash- star (/*). End with slash-star (/*).
Start with two slashes (//). End with two slashes (//).
Start with two slashes and a star (//*). End with a star-slash (*/).
Start with two slashes (//). End when the line ends.(*)
Start with a slash-star (/*). End with a star-slash (*/).(*)
Correct
6. What is the purpose of adding comments in the code?
Provide an explanation about the code to the programmer. (*)
To provide better security to the program.
It increases the execution time of the code.
Provide good look and feel of the code.
Correct

7. You have a beautiful garden at home. On Sunday, you start budding your rose plant to
make few more samples of rose plants to plant in the garden. Can you categorize how this
scenario could be represented by classes and instances?
Rose plant is the class and the samples generated from the rose plant are instances of that
class. (*)
Samples are the class and the rose plant is the instances of samples.
Samples of the rose plant are called classes and not the actual rose plant.
Rose plant is the object and samples are not instances of the plant because they have not
grown yet.
Correct
8. There are several fields and methods in a Shirt class. Which of the following could be a
method in the Shirt class?
color
price
size
getShirtSize() (*)
Correct

9. In object oriented programming, there is an emphasis on which of the following two:
Writing algorithms.
Modeling objects.(*)
Creation of procedures.
Object interaction without a prescribed order.(*)
Incorrect. Refer to Section 2 Lesson 3.

10. You design a Circle class with various fields and methods. Which of the following could
be fields in this class? Distinguish which of these are between the properties and behavior.
calculateDiameter()
calculateCircumference()
calculateArea()
radius(*)
color(*)
Incorrect. Refer to Section 2 Lesson 3.
11. 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);
}
}
name
empId
displaySalary() (*)
salary
Correct

12. During the Design phase of software development, the programmer implements features
gathered during the Requirement phase.
True
False (*)
Incorrect. Refer to Section 2 Lesson 1.

13. Which of the following are adequate definitions for components of the Spiral Model of
Development?
Develop: Collect all specified instructions
Requirements: Start the development
Design: Plan the approach(*)
Test: Run the code and verify results(*)
Incorrect. Refer to Section 2 Lesson 1.

14. If the requirement step of the Spiral Model of development is forgotten, which of the
following could occur?
Code becomes messy.
The Program gives inaccurate results.
Solutions seem elusive.
Required software features are missing from the program. (*)
Incorrect. Refer to Section 2 Lesson 1.

15. The Spiral Model reflects an iterative development process.


True (*)
False
Correct

SOAL QUIZ 3.1


Section 3 Quiz 1 - L1-L2
(Answer all questions in this section)
1. Which two are recommended practices for naming final variables?
Capitalize every letter(*)
Separate words with an underscore(*)
Capitalize first letter
Separate words with an space
Incorrect. Refer to Section 3 Lesson 2.

2. Which of the following data types is the largest?


byte
short
int
long (*)
Correct
3. What value is assigned to x?

int x = 25 - 5 * 4 / 2 - 10 + 4;
8
9 (*)
34
7
Correct

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


const
final (*)
static
break
Correct

5. How many bits are in a byte?


2
4
6
7
8 (*)
Correct
6. Assuming x is an int, which of the following are ways to increment the value of x by 1?
x = x +1;(*)
x = +1;
x+;
x++;(*)
x += 1;(*)
Incorrect. Refer to Section 3 Lesson 2.

7. What is the output? public static void main(String args[]) {


  int x = 100;
  int y = x;
  y++;
  System.out.println("Value of x is " + x);
  System.out.println("Value of y is " + y);
}
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct

8. What is the range of the byte data type?


–27 to 27–1 (*)
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct

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


String x = Java;
String “x” = “Java”;
String x= “Java”; (*)
String “x” = Java;
Correct

10. 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);
 }
}
2
a (*)
int
Welcome
Incorrect. Refer to Section 3 Lesson 1.
11. Which two data types are appropriate for their variable?
Mark for Review

(1) Points
String firstName = “Alex”;(*)
double checkingAmount = 1500;(*)
int averageDollarAmount = 19.95;
boolean age = 20;
Correct
12. Java is a strongly typed language; therefore you must declare a data type for all
variables.
True (*)
False
Correct

13. Assigning a value to the variable is called “initialization”.


True (*)
False
Incorrect. Refer to Section 3 Lesson 1.

14. Which two statements will not compile?


int age=20;
int abc = 10;
double salary = 20000.34;
int break=10;(*)
double double=10;(*)
Incorrect. Refer to Section 3 Lesson 1.

15. What is the output?

public class Hello {


  public static void main(String args[]) {
    String str = ”Hello”;
    str = ”World”;
   System.out.println(str);
 }
}
Hello World
Hello
Hello
World
World (*)
Incorrect. Refer to Section 3 Lesson 1.

1. What value is assigned to x?

int x = 25 - 5 * 4 / 2 - 10 + 4;
8
9 (*)
34
7
Correct
2. What is the range of the byte data type?
–27 to 27–1 (*)
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct

3. What is the output?

public class Person {


  public static void main(String args[]) {
  int age = 20;
  System.out.println("Value of age: " +age);
  age = 5 + 3;
  System.out.println("Value of age: " +age);
  age = age + 1;
  age++;
  System.out.println("Value of age: " +age);
 }
}
Value of age: 20
Value of age: 8
Value of age: 10 (*)
Value of age: 20
Value of age: 28
Value of age: 38
Value of age: 20
Value of age: 208
Value of age: 20810
Value of age: 20
Value of age: 8
Value of age: 9
Correct

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


const
final (*)
static
break
Correct

5. What is the output? public static void main(String args[]) {


  int x = 100;
  int y = x;
  y++;
  System.out.println("Value of x is " + x);
  System.out.println("Value of y is " + y);
}
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct
6. How many bits are in a byte?
2
4
6
7
8 (*)
Correct

7. Assuming x is an int, which of the following are ways to increment the value of x by 1?
x = x +1;(*)
x = +1;
x+;
x++;(*)
x += 1;(*)
Correct

8. This declaration represents a long data type.


long a = 123L;
True (*)
False
Correct

9. What is the output?

public class Hello {


  public static void main(String args[]) {
    String str = ”Hello”;
    str = ”World”;
   System.out.println(str);
 }
}
World (*)
Hello
World
Hello World
Hello
Correct

10. Which two data types are appropriate for their variable?


double checkingAmount = 1500;(*)
String firstName = “Alex”;(*)
boolean age = 20;
int averageDollarAmount = 19.95;
Correct
11. 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);
 }
}
a (*)
2
int
Welcome
Correct

12. Which two are valid?


double doubleVar1; doubleVar2 = 3.1.
double doubleVar1, double doubleVar2 = 3.1;
double doubleVar1 = 3.1; double doubleVar2 = 3.1;(*)
double doubleVar1, doubleVar2 = 3.1;(*)
Correct

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

14. Assigning a value to the variable is called “initialization”.


True (*)
False
Correct

15. Identify the names of two variables used in the given code.

public class Variables {


  public static void main(String args[]) {
   String strVal = "Hello";
  int intVal = 0;
   System.out.println("Integer: " +intVal)
 }
}
Hello
intVal(*)
int
strVal(*)
String
Correct

1. The Java compiler automatically promotes byte, short, and chars data type values to int
data type.
True (*)
False
Correct

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


NumberFormatException (*)
ArithmeticException
NullPointerException
ValueNotFoundException
Correct

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


int intVar1 = "100";
nt intVar1 = (int)"100";
int intVar1 = Integer.parseInt("100"); (*)
int intVar1 = Integer.parseInt("One Hundred");
Correct

4. A double with the value of 20.5 is cast to an int. What is the value of the int?
25
21
20 (*)
20.5
Correct

5. What is the correct way to cast a long to an int?


int longToInt = 20L;
int longToInt = (int)20L; (*)
int longToInt = int 20L;
int longToInt = 20L(int);
Correct
6. When the result of an expression is assigned to a temporary memory location, what is the
size of memory allocated?
The size of the smallest data type used in the expression.
The size of the largest data type used in the expression. (*)
The size of the any data type used in the expression.
A default size is allocated.
Correct

7. Which two statements compile?


String name = “J”;(*)
String name = new String ( ‘Java’);
String name = “Java”;(*)
String name = ‘Java’;
Correct

8. In Java, char is a primitive data type, while String is an object data type.
True (*)
False
Correct

9. The print() method prints to the console and automatically creates a line.
True
False (*)
Incorrect. Refer to Section 3 Lesson 3.

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


True (*)
False
Correct
11. Double quotes may be used with char literal values.
True
False (*)
Correct

12. An Object cannot have String objects as properties.


True
False (*)
Incorrect. Refer to Section 3 Lesson 3.

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

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


A Scanner object opens a stream for collecting input.(*)
Scanners cannot read text files.
A Scanner’s delimiter can be changed.(*)
A Scanner object doesn’t have fields and methods.
Incorrect. Refer to Section 3 Lesson 5.

15. You write a statement that assigns a value to a String variable as shown below.

String input = ”This is Java Program”;

This way of assigning values to variables is known as hard-coding.


True (*)
False
Correct
1. In Java, char is a primitive data type, while String is an object data type.
o True (*)
o False
2. An Object cannot have String objects as properties.
o True
o False (*)
3. A character preceded by backslash is called an escape sequence.
o True (*)
o False
4. Char data types cannot handle multiple characters.
o True (*)
o False
5. Given the expression:
String message = ”Hello World”;
Which is the String Literal?
o String message
o String message = ”Hello World”;
o message
o Hello World (*)
6. The print() method prints to the console and automatically creates a line.
o True
o False (*)
7. Which is a valid way to parse a String as an int?
o int intVar1 = Integer.parseInt(“One Hundred”);
o int intVar1 = “100”;
o int intVar1 = Integer.parseInt(“100”); (*)
o nt intVar1 = (int)”100″;
8. Which two statements are true about type casting? (Choose all correct answers)
o Type casting lowers the range of possible values. (*)
o Type casting cannot be performed on equations.
o Type casting changes the type of the value stored. (*)
o Type casting retains the size of the value or the original data type.
9. What is the correct way to cast a long to an int?
o int longToInt = int 20L;
o int longToInt = 20L;
o int longToInt = 20L(int);
o int longToInt = (int)20L; (*)
10. Automatic promotion from smaller data type to a larger data type is not allowed in
Java.
o True
o False (*)
11. A double with the value of 20.5 is cast to an int. What is the value of the int?
o 20 (*)
o 5
o 25
o 21
12. Which two statements are correct about the usage of an underscore? (Choose all
correct answers)
o Underscores help make large numbers more readable. (*)
o Underscores help the compiler interpret large numbers.
o Underscores change the value of the number.
o Underscores do not affect the value of the variable. (*)
13. The Scanner class accepts input in which form?
o Callables
o Integer
o Future
o Tokens (*)
14. It’s best-practice to close the Scanner stream when finished
o True (*)
o False
15. The Scanner class considers space as the default delimiter while reading the input.
o True (*)
o False
16. A short data type can be promoted to which of the following types? (Choose all
correct answers)
o double (*)
o boolean
o byte
o long (*)
o int (*)
17. What is the correct way to cast a long to an int?
o int longToInt = 20L;
o int longToInt = 20L(int);
o int longToInt = (int)20L; (*)
o int longToInt = int 20L;
18. The Java compiler automatically promotes byte, short, and chars data type values to
int data type.
o True (*)
o False
19. Which exception occurs because a String cannot be parsed as an int?
o NumberFormatException (*)
o ArithmeticException
o NullPointerException
o ValueNotFoundException
20. Which two statements are true about type casting? (Choose all correct answers)
o Type casting cannot be performed on equations.
o Type casting retains the size of the value or the original data type.
o Type casting changes the type of the value stored. (*)
o Type casting lowers the range of possible values. (*)
21. Which is a valid way to parse a String as an int?
o int intVar1 = “100”;
o nt intVar1 = (int)”100″;
o int intVar1 = Integer.parseInt(“One Hundred”);
o int intVar1 = Integer.parseInt(“100”); (*)
22. in readies Scanner to collect input from the console.
o True (*)
o False
23. The Scanner class considers space as the default delimiter while reading the input.
o True (*)
o False
24. The Scanner class accepts input in which form?
o Callables
o Tokens (*)
o Integer
o Future
25. Which is the correct declaration for a char data type?
o char size = ’M’; (*)
o char size = “M”;
o char size = ’Medium’;
o char size = “Medium”;
26. In Java, char is a primitive data type, while String is an object data type.
o True (*)
o False
27. What is the output?
public static void main(String args[]) {
String greet1 = “Hello”;
String greet2 = “World”;
String message2 = greet1 +” ” +greet2 +” ” +2016 +”!”;
out.println(message2);
}
o “Hello World 2016”
o “Hello” “World” “2016” “!”
o Hello World
o Hello World 2016 ! (*)
28. Char data types cannot handle multiple characters.
o True (*)
o False
29. Given the expression:
String message = ”Hello World”;
Which is the String Literal?
o Hello World (*)
o String message
o message
o String message = ”Hello World”;
30. Which two statements are true about String concatenation. (Choose all correct
answers)
o String concatenation can be done with String variables and String
Literals. (*)
o Strings can be combined using the ‘+’ operator (*)
o String concatenation cannot be done with numbers.
o String concatenation cannot be done with more than two String Literals.

1. What is parsing?
Converting numeric data to text
Converting text to numeric data (*)
Converting numeric data to a specified numeric data type
Reading text from numeric data
Correct

2. A double with the value of 20.5 is cast to an int. What is the value of the int?
21
20.5
20 (*)
25
Correct

3. What is the correct way to cast a long to an int?


int longToInt = 20L;
int longToInt = int 20L;
int longToInt = 20L(int);
int longToInt = (int)20L; (*)
Correct

4. A short data type can be promoted to which of the following types?
double(*)
long(*)
int(*)
boolean
Correct

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


int intVar1 = "100";
int intVar1 = Integer.parseInt("One Hundred");
int intVar1 = Integer.parseInt("100"); (*)
nt intVar1 = (int)"100";
Correct
6. Automatic promotion from smaller data type to a larger data type is not allowed in Java.
True
False (*)
Correct

7. You write a statement that assigns a value to a String variable as shown below.

String input = ”This is Java Program”;

This way of assigning values to variables is known as hard-coding.


True (*)
False
Correct

8. The Scanner class considers space as the default delimiter while reading the input.
True (*)
False
Correct

9. The Scanner class accepts input in which form?


Tokens (*)
Integer
Future
Callables
Correct

10. Which two statements compile?


String name = “J”;(*)
String name = “Java”;(*)
String name = ‘Java’;
String name = new String ( ‘Java’);
Correct
11. Char data types cannot handle multiple characters.
True (*)
False
Correct

12. In Java, char is a primitive data type, while String is an object data type.
True (*)
False
Correct

13. Which two statements are true about String concatenation.


String concatenation cannot be done with more than two String Literals.
String concatenation cannot be done with numbers.
String concatenation can be done with String variables and String Literals.(*)
Strings can be combined using the ‘+’ operator(*)
Correct

14. Which two statements compile?


String size = “M”;(*)
char size = ’m’;(*)
String size = ‘M’;
char size = ”m”;
Correct

15. What is the output?

public static void main(String args[]) {


  String greet1 = "Hello";
  String greet2 = "World";
  String message2 = greet1 +" " +greet2 +" " +2016 +"!";
  System.out.println(message2);
}
Hello World 2016 ! (*)
Hello World
“Hello World 2016”
“Hello” “World” “2016” “!”
Correct

1. Once an object is instantiated, how might its fields and methods be accessed in Java
o Using the comma(,) operator
o Using the double-colon(::) operator
o Using the dot(.) operator (*)
o Using the colon(:) operator
2. 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){
out.println(x/y);
}
o testMethod(3.5, 10);
o testMethod(3.5);
o testMethod(10, 3.5); (*)
o testMethod(10);
o testMethod(10, 3.5, 0);
3. Which of the following statements are true (Choose all correct answers)
o Methods cannot be written with parameters.
o Methods can be written with any number of parameters. (*)
o Parameter values can never be used within the method code block.
o Parameter values can be used within the method code block. (*)
o Methods can never be written with more than four parameters.
4. Object instantiation is done using what keyword?
o System
o instance
o new (*)
o void
5. Which of the following scenarios would be ideal for writing a method
o To group similar data types together
o When you don’t want to repeat similar lines of code to describe an
object’s behavior. (*)
o For every five to six lines of code.
o When you don’t find similar lines of code to describe an object’s behavior.
6. Methods allow all instance of a class to share same behaviors.
o True (*)
o False
7. An argument is a value that’s passed during a method call
o True (*)
o False
8. Which of the following two operations are appropriate for the main method (Choose
all correct answers)
o Creating instances of objects (*)
o Calling an instance object’s field and methods. (*)
o Assigning memory to the variables
o Calling local variables declared within a class’s method
9. Which of the following wild card character is used to import all the classes in a
particular package
o !
o ~
o ;
o * (*)
10. Which two are valid import statements of the Scanner class? (Choose all correct
answers)
o import java.*;
o import java.util.Scanner; (*)
o import java.util;
o import java.util.*; (*)
11. Which package is implicitly imported
o io
o lang (*)
o awt
o math
12. The JFrame and JOptionPane classes are in the javax.swing package. Which two
will import those classes? (Choose all correct answers)
o import javax.swing.J*;
o import javax.swing.*; (*)
o import javax.swing;
o import javax.swing.JOptionPane;
o import javax.swing.JFrame; (*)
13. The classes of the Java class library are organized into packages
o True (*)
o False
14. The import statement consists of two parts.
import package.className;
One is the package name and the other is the classname
o True (*)
o False
15. Which statement is true about packages
o A package doesn’t contain a group of related classes.
o Packages of the Java class library do not contain related classes.
o A package makes it difficult to locate the related classes.
o A package contains a group of related classes. (*)

1. Import statements are placed above the class definition.


True (*)
False
Correct

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


Code readability is reduced. (*)
The compiler runs longer.
Performance of the code is reduced.
Memory usage is increased.
Incorrect. Refer to Section 4 Lesson 2.

3. The classes of the Java class library are organized into packages.
True (*)
False
Correct

4. Given the import statement:


import java.awt.font.TextLayout;
which is the package name?
java.awt.font (*)
java
awt.font
java.awt
Incorrect. Refer to Section 4 Lesson 2.

5. Which statement is true about packages?


Packages of the Java class library do not contain related classes.
A package makes it difficult to locate the related classes.
A package doesn’t contain a group of related classes.
A package contains a group of related classes. (*)
Correct
6. The JFrame and JOptionPane classes are in the javax.swing package. Which two will
import those classes?
import javax.swing;
import javax.swing.*;(*)
import javax.swing.J*;
import javax.swing.JOptionPane;
import javax.swing.JFrame;(*)
Correct

7. Which of the following wild card character is used to import all the classes in a particular
package?
* (*)
!
~
;
Correct

8. void type methods don’t return any values


True (*)
False
Correct

9. You’re designing banking software and need to store 10000 customer accounts with
information on the accountholder’s name, balance, and interest rate. The best approach is
store 30000 separate variables in the main method.
True
False (*)
Incorrect. Refer to Section 4 Lesson 1.

10. Which of the following statements are true?


Parameter values can be used within the method code block.(*)
Methods cannot be written with parameters.
Methods can never be written with more than four parameters.
Parameter values can never be used within the method code block.
Methods can be written with any number of parameters.(*)
Incorrect. Refer to Section 4 Lesson 1.
11. Which of the following two operations are appropriate for the main method?
Creating instances of objects(*)
Calling an instance object’s field and methods.(*)
Calling local variables declared within a class’s method
Assigning memory to the variables
Incorrect. Refer to Section 4 Lesson 1.

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


To group similar data types together
For every five to six lines of code.
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.
Correct

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


True
False (*)
Incorrect. Refer to Section 4 Lesson 1.

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

Employee emp = new Employee();


emp.calculateSalary(100000, 3.2, 15);
emp.calculateSalary(100000, 3.2, 15);
emp
100000, 3.2, 15 (*)
calculateSalary(100000, 3.2, 15);
Correct

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


True (*)
False
Correct

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Random
Number”.
1. Which class is used to generate random number?
a) java.lang.Object
b) java.util.randomNumber
c) java.util.Random
d) java.util.Object
View Answer
Answer: c
Explanation: java.util.random class is used to generate random numbers in java program.
2. Which method is used to generate boolean random values in java?
a) nextBoolean()
b) randomBoolean()
c) previousBoolean()
d) generateBoolean()
View Answer
Answer: a
Explanation: nextBoolean() method of java.util.Random class is used to generate random
numbers.
3. What is the return type of Math.random() method?
a) Integer
b) Double
c) String
d) Boolean
View Answer
Answer: b
Explanation: Math.random() method returns floating point number or precisely a double.
4. Random is a final class?
a) True
b) False
View Answer
Answer: b
Explanation: Random is not a final class and can be extended to implement the algorithm as
per requirement.
5. What is the range of numbers returned by Math.random() method?
a) -1.0 to 1.0
b) -1 to 1
c) 0 to 100
d) 0.0 to 1.0
View Answer
Answer: d
Explanation: Math.random() returns only double value greater than or equal to 0.0 and less
than 1.0.
6. How many bits are used for generating random numbers?
a) 32
b) 64
c) 48
d) 8
View Answer
Answer: c
Explanation: Random number can accept 64 bits but it only uses 48 bits for generating
random numbers.
7. What will be the output of the following Java code snippet?
int a = random.nextInt(15) + 1;
a) Random number between 1 to 15, including 1 and 15
b) Random number between 1 to 15, excluding 15
c) Random number between 1 to 15, excluding 1
d) Random number between 1 to 15, excluding 1 and 15
View Answer
Answer: a
Explanation: random.nextInt(15) + 1; returns random numbers between 1 to 15 including 1
and 15.
8. What will be the output of the following Java code snippet?
int a = random.nextInt(7) + 4;
a) Random number between 4 to 7, including 4 and 7
b) Random number between 4 to 7, excluding 4 and 7
c) Random number between 4 to 10, excluding 4 and 10
d) Random number between 4 to 10, including 4 and 10
View Answer
Answer: d
Explanation: random.nextInd(7) + 4; returns random numbers between 4 to 10 including 4
and 10. it follows “nextInt(max – min +1) + min” formula.
9. Math.random() guarantees uniqueness?
a) True
b) False
View Answer
Answer: b
Explanation: Math.random() doesn’t guarantee uniqueness. To guarantee uniqueness we
must store the generated value in the database and compare against already generated
values.
10. What is the signature of Math.random() method?
a) public static double random()
b) public void double random()
c) public static int random()
d) public void int random()
View Answer
Answer: a
Explanation: public static double random() is the utility method provided by Math class which
returns double.
1. Which class is used to generate random numbers?
Double
Number
Random (*)
Integer
Correct

2. You need to generate random integer values between 0 and 80 (inclusive). Which
statement should you use?
nextInt(81); (*)
nextInt(0-79);
nextInt(80);
nextInt();
Incorrect. Refer to Section 4 Lesson 4.
3. You need to generate random integer values in the range 2 through 10. This code
fragment will produce the desired result.

Random r = new Random();


r.nextInt(9) + 2;
True (*)
False
Correct

4. Which values are returned by the method nextBoolean();


An integer value.
Nothing is returned.
Returns the next value.
Either a true or false. (*)
Correct

5. String objects are immutable.


True (*)
False
Correct
6. The indexOf() method returns the index value of a character in the string.
True (*)
False
Correct

7. What is the output of the following code?

public static void main(String args[]) {


   String firstString = "Java";
   firstString = firstString.concat("World");
   System.out.println(firstString);
}
Java World
World
JavaWorld (*)
Java
Correct

8. What is the output?

public static void main(String args[]) {


   String alphaNumeric = "Java World!" + 8;
   System.out.println(alphaNumeric);
}
Compilation error.
Java World!8 (*)
Java World! + 8
Java World! 8
Correct

9. The String concat() method concatenates only String data types.


True (*)
False
Correct

10. The String class must be imported using java.lang.String;


True
False (*)
Incorrect. Refer to Section 4 Lesson 3.
11. The replaceFirst() method replaces only the first occurrence of matching character
pattern in a string.
True (*)
False
Correct

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


Math methods can be invoked with Strings as arguments.
You don’t have to worry about the data type returned from a Math method.
The Math methods can be invoked without creating an instance of a Math object.(*)
Common math functions like square root are taken care of in the language.(*)
Incorrect. Refer to Section 4 Lesson 5.

13. Every method of the Math class returns a numerical result.


True (*)
False
Correct

14. The Math class methods can be called without creating an instance of a Math object.
True (*)
False
Correct

15. What is the package name which contains Math class?


java.net
java.awt
java.io
java.lang (*)
Incorrect. Refer to Section 4 Lesson 5.
1. Which two are the features of the Math class?
Math methods can be invoked with Strings as arguments.
You don’t have to worry about the data type returned from a Math method.
The Math methods can be invoked without creating an instance of a Math object.(*)
Common math functions like square root are taken care of in the language.(*)
Correct

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


True (*)
False
Correct

3. Which is NOT true?


Static methods can be invoked through an instance of a class
Static methods can be invoked through the class name.
Static methods must be of return void. (*)
A class can have multiple static methods.
Incorrect. Refer to Section 4 Lesson 5.

4. What is the package name which contains Math class?


java.lang (*)
java.io
java.net
java.awt
Correct

5. A String is a sequence characters.


True (*)
False
Correct
6. What is the output?

public static void main(String args[]) {


   String alphaNumeric = "Java World!" + 8;
   System.out.println(alphaNumeric);
}
Compilation error.
Java World! 8
Java World!8 (*)
Java World! + 8
Correct

7. What is the output of the following code?

public static void main(String args[]) {


   String firstString = "Java";
   firstString = firstString.concat("World");
   System.out.println(firstString);
}
Java
JavaWorld (*)
World
Java World
Correct

8. The String concat() method concatenates only String data types.


True (*)
False
Correct

9. The replaceFirst() method replaces only the first occurrence of matching character pattern
in a string.
True (*)
False
Correct

10. The indexOf() method returns the index value of a character in the string.
True (*)
False
Correct
11. String objects are immutable.
True (*)
False
Correct

12. You need to generate random integer values in the range 2 through 10. This code
fragment will produce the desired result.

Random r = new Random();


r.nextInt(9) + 2;
True (*)
False
Correct

13. You need to generate random integer values between 0 and 80 (inclusive). Which
statement should you use?
nextInt();
nextInt(0-79);
nextInt(81); (*)
nextInt(80);
Correct

14. Which values are returned by the method nextBoolean();


An integer value.
Nothing is returned.
Returns the next value.
Either a true or false. (*)
Correct

15. Using the Random class requires an import statement.


True (*)
False
Correct

1. What is the output?

public static void main(String args[]) {


   char grade ='E';
   if (grade == 'A') {
      System.out.println("Excellent performer");
   }else if (grade == 'B') {
      System.out.println("Good Performer");
   }else if (grade == 'C') {
   System.out.println("Average Performer");
   }else {
      System.out.println("Below Average Performer");
   }
}
Below Average Performer (*)
Below Performer
Not a Good Performer
Excellent performer
Correct

2. A break statement causes control to transfer to the end of the switch statement.
True (*)
False
Correct

3. The switch statement is a more efficient way to write code when dealing with a large
range of unknown values.
True
False (*)
Incorrect. Refer to Section 5 Lesson 3.

4. 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");
   }
}

Compilation error
Vowels
Vowels
Consonants (*)
Correct

5. An employee is eligible for a bonus based on certain criteria.


Under what conditions does “Eligible for a bonus” print?

int rating;
int experience;
if (rating > 1 && experience == 5) {
   System.out.println (“Eligible for a bonus”);
}
5 rating and 1 experience
5 experience and 1 rating
5 experience and 2 or more rating (*)
Less than 5 experience and 1 rating.
Incorrect. Refer to Section 5 Lesson 2.

6. Which two are not logical operators?


&&
%(*)
!
+(*)
||
Correct

7. What is the result?

public static void main(String[] args) {


   int point = 10;
   String s = (point == 1 ? "point" : "points");
   System.out.println("I scored " +point +" " +s );
}
I scored 10 points (*)
I scored 1 point
I scored 1 point 10 points
Compilation error
Correct

8. 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");
}
When rewardPoints is more than 1000 and purchase is 1000
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(*)
Correct

9. Which three are conditional statements?


if/else statement(*)
if statement(*)
switch statement(*)
do while loop
for loop
Correct

10. An if/else statement is used when you need to choose between two alternatives.
True (*)
False
Correct

11. What is the output?


public static void main(String[] args) {
   String name = "Java";
   String language = "Programming";
   String fullName = name + language;
   boolean test = fullName.equals(name + language);
   System.out.println(test);
}
JavaProgramming
True (*)
False
Java Programming
Incorrect. Refer to Section 5 Lesson 1.

12. Which are used in a boolean expression?


Variables(*)
Errors
Loops
Operators(*)
Incorrect. Refer to Section 5 Lesson 1.

13. The equal sign (=) is used to make an assignment, whereas the == sign merely makes a
comparison and returns a boolean.
True (*)
False
Correct

14. Which operator is used to test if both sides of a boolean expression are equal?
=
>=
== (*)
<=
Correct

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


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

1. An if/else statement is used when you need to choose between two
alternatives.
True (*)
False
Correct

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


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

3. Which three are conditional statements?


if statement(*)

switch statement(*)

for loop

do while loop

if/else statement(*)
Incorrect. Refer to Section 5 Lesson 1.

4. How should Strings be compared?


==
=
~=
The equals() method (*)
Correct

5. The equal sign (=) is used to make an assignment, whereas the ==


sign merely makes a comparison and returns a boolean.
True (*)
False
Correct
6. What is the output?

public static void main(String[] args) {


   String name = "Java";
   String language = "Programming";
   String fullName = name + language;
   boolean test = fullName.equals(name + language);
   System.out.println(test);
}
JavaProgramming
False
Java Programming
True (*)
Correct

7. A String comparison with == compares the Strings’ locations in


memory and not the content of the String.
True (*)
False
Correct

8. Which two are not logical operators?


&&

+(*)

%(*)

||
Correct

9. What is the result?

public static void main(String[] args) {


   int point = 10;
   String s = (point == 1 ? "point" : "points");
   System.out.println("I scored " +point +" " +s );
}
Compilation error
I scored 1 point
I scored 1 point 10 points
I scored 10 points (*)
Correct

10. In Java, an if statement can be nested inside another if statement.


True (*)
False
Correct
11. 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

12. The switch statement is a more efficient way to write code when


dealing with a large range of unknown values.
True
False (*)
Correct

13. A break statement causes control to transfer to the end of the switch
statement.
True (*)
False
Correct

14. What is the output?

char grade = 'A';


switch (grade) {
   case 'A':
      System.out.println("Congratulations!");    case 'B':
      System.out.println("Good work");
   case 'C':
      System.out.println("Average");
   case 'D':
      System.out.println("Barely passing");
   case 'F':
      System.out.println("Failed");
}

Failed
A
Congratulations!
Congratulations! Good Work Average Barely Passing Failed (*)
Incorrect. Refer to Section 5 Lesson 3.

15. 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
Consonants (*)
Vowels
Compilation error
Correct

Langsung saja check this out soal dan jawaban Mid Term – Java Foundation-nya!

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


o Creation of procedures.
o Modeling objects. (*)
o Object interaction without a prescribed order. (*)
o Writing algorithms.
2. An object may interact with another object by invoking methods.
o True (*)
o False
3. In object oriented programming, an object comprises of properties and behaviors where
properties represented as fields of the object and behavior is represented as method.
o True (*)
o False
4. A software feature may allow the user to perform a specific task.
o True (*)
o False
5. During the Design phase of software development, the programmer implements features
gathered during the Requirement phase.
o True
o False (*)
6. During the Testing phase of software development, which of the following are the tasks
undertaken by the programmer? Listing required features.
o Finding the bugs. (*)
o Fixing the bugs. (*)
o Planning the order to implement features.
7. A Java program can be written in the single line.
o True (*)
o False
8. Which two are the correct syntax for adding comments? (Choose all correct answers)
o Start with two slashes (//). End when the line ends. (*)
o Start with two slashes (//). End with two slashes (//).
o Start with a slash- star (/*). End with slash-star (/*).
o Start with two slashes and a star (//*). End with a star-slash (*/).
o Start with a slash-star (/*). End with a star-slash (*/). (*)
9. Code within curly braces is called a “Block of code”.
o True (*)
o False
10. char is the primitive textual data type in Java
o True (*)
o False
11. Which two statements compile? (Choose all correct answers)
o String name = “Java”; (*)
o String name = new String ( ‘Java’);
o String name = “J”; (*)
o String name = ‘Java’;
12. Which is the correct declaration for a char data type?
o char size = “Medium”;
o char size = ’Medium’;
o char size = “M”;
o char size = ’M’; (*)

13. What is the output?


public class Welcome {
public static void main(String args[]) {
out.println(“This is my first program”);
int a = 2;
System.out.println(“a is” + a);
}
}
o This is my first program a is + a
o a=2
o This is my first program a is 2 (*)
o This is my first program
14. Which two data types are appropriate for their variable?
o String firstName = “Alex”; (*)
o int averageDollarAmount = 19.95;
o boolean age = 20;
o double checkingAmount = 1500; (*)
15. Which two are valid? (Choose all correct answers)
o double doubleVar1, doubleVar2 = 3.1; (*)
o double doubleVar1, double doubleVar2 = 3.1;
o double doubleVar1; doubleVar2 = 3.1.
o double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)

16. Which two statements are true about type casting? (Choose all correct answers)
o Type casting cannot be performed on equations.
o Type casting retains the size of the value or the original data type.
o Type casting changes the type of the value stored. (*)
o Type casting lowers the range of possible values. (*)
17. Which is a valid way to parse a String as an int?
o int intVar1 = Integer.parseInt(“100”); (*)
o nt intVar1 = (int)”100″;
o int intVar1 = Integer.parseInt(“One Hundred”);
o int intVar1 = “100”;
18. Which exception occurs because a String cannot be parsed as an int?
o NumberFormatException (*)
o ArithmeticException
o NullPointerException
o ValueNotFoundException
19. in readies Scanner to collect input from the console.
o True (*)
o False
20. The Scanner class accepts input in which form?
o Integer
o Callables
o Tokens (*)
o Future

21. 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;
o True (*)
o False
22. What is the output?
public class Person {
public static void main(String args[]) {
int age = 20;
out.println(“Value of age: ” +age);
age = 5 + 3;
System.out.println(“Value of age: ” +age);
age = age + 1;
age++;
System.out.println(“Value of age: ” +age);
}
}
o Value of age: 20
Value of age: 8
Value of age: 10 (*)
o Value of age: 20
Value of age: 28
Value of age: 38
o Value of age: 20
Value of age: 208
Value of age: 20810
o Value of age: 20
Value of age: 8
Value of age: 9

23. What is the range of the byte data type?


o –27 to 27–1 (*)
o –215 to 215–1
o –231 to 231–1
o –263 to 263–1
24. This declaration represents a long data type.
long a = 123L;
o True (*)
o False
25. What is the output?
public static void main(String args[]) {
String greeting = “Java World!”;
String w = greeting.replace(“a”, “A”);
out.println(w);
}
o JavA World!
o World!
o JAva World!
o JAvA World! (*)
26. The indexOf() method returns the index value of a character in the string.
o True (*)
o False
27. The String class must be imported using java.lang.String;
o True
o False (*)
28. The String concat() method concatenates only String data types.
o True (*)
o False
29. The import statement consists of two parts.
import package.className;
One is the package name and the other is the classname.
o True (*)
o False
30. Which of the following wild card character is used to import all the classes in a particular
package?
o ~
o !
o ;
o * (*)
31. Import statements are placed above the class definition.
o True (*)
o False
32. Given the import statement:
import java.awt.font.TextLayout;
which is the package name?
o font
o awt.font (*)
o awt
o java
33. The Math class methods can be called without creating an instance of a Math object.
o True (*)
o False
34. What is the package name which contains Math class?
o net
o lang (*)
o awt
o io
35. Methods allow all instance of a class to share same behaviors.
o True (*)
o False

36. An argument is a value that’s passed during a method call


o True (*)
o False
37. Which of the following are the arguments in the following method?
Employee emp = new Employee();
calculateSalary(100000, 3.2, 15);
o calculateSalary(100000, 3.2, 15);
o calculateSalary(100000, 3.2, 15);
o 100000, 3.2, 15 (*)
o emp
38. How many arguments does the following method accept?
public void simpleInterest(double principal, int noofYears, double interestRate){
out.println(“The interest rate is ” +interestRate );
}
o 1
o 2
o 0
o 3 (*)
39. Which class is used to generate random numbers?
o Double
o Random (*)
o Integer
o Number
40. You need to generate random integer values between 0 and 80 (inclusive). Which statement
should you use?
o nextInt(0-79);
o nextInt(80);
o nextInt();
o nextInt(81); (*)
41. You need to generate random integer values in the range 2 through 10. This code fragment
will produce the desired result.
Random r = new Random();
nextInt(9) + 2; Mark for Review
o True (*)
o False
42. In the AND (&&) test, if the first expression on the left hand side is false, then there is no need
to evaluate the second statement.
o True (*)
o False
43. In Java, an if statement can be nested inside another if statement.
o True (*)
o False
44. An employee is eligible for a bonus based on certain criteria.
Under what conditions does “Eligible for a bonus” print?
int rating;
int experience;
if (rating > 1 && experience == 5) {
out.println (“Eligible for a bonus”);
}
o Less than 5 experience and 1 rating.
o 5 experience and 1 rating
o 5 experience and 2 or more rating (*)
o 5 rating and 1 experience

45. The equal sign (=) is used to make an assignment, whereas the == sign merely makes a
comparison and returns a boolean.
o True (*)
o False
46. A String comparison with == compares the Strings’ locations in memory and not the content
of the String.
o True (*)
o False
47. What is the output?
public static void main(String[] args) {
int age = 43;
if (age == 43){
out.print(“Bob is 43 “);
}
if (age == 50){
System.out.print(“Bob is 50 “);
}
}
o Bob is 43 Bob is 50
o Bob is 50
o No output
o Bob is 43 (*)
48. Which are used in a boolean expression? (Choose all correct answers)
o Variables (*)
o Loops
o Operators (*)
o Errors
49. A break statement causes control to transfer to the end of the switch statement.
o True (*)
o False
50. Which two of the following data types can be used in a switch statement? (Choose all correct
answers)
o boolean
o String (*)
o float
o int (*)

S-ar putea să vă placă și