0% found this document useful (0 votes)
47 views11 pages

Kuis Oracle Sabitha

This document contains a quiz with multiple choice questions about Java programming concepts like comments, whitespace, objects, methods, data types, strings, random numbers, and the Math class. It tests knowledge of syntax, object-oriented principles, primitive vs. object types, casting, concatenation, immutability, and string methods. The questions have single or multiple correct answers and provide feedback on right and wrong responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views11 pages

Kuis Oracle Sabitha

This document contains a quiz with multiple choice questions about Java programming concepts like comments, whitespace, objects, methods, data types, strings, random numbers, and the Math class. It tests knowledge of syntax, object-oriented principles, primitive vs. object types, casting, concatenation, immutability, and string methods. The questions have single or multiple correct answers and provide feedback on right and wrong responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Section 2 Quiz

(Answer all questions in this section)


1. Which two are the correct syntax for adding comments?
(Choose all correct answers)

Start with two slashes and a star (//*). End with a star-slash (*/).
Start with two slashes (//). End when the line ends. (*)
Start with two slashes (//). End with two slashes (//).
Start with a slash- star (/*). End with slash-star (/*).
Start with a slash-star (/*). End with a star-slash (*/). (*)
Correct
(1/1) Points
2. Which of the following are considered Whitespace?
(Choose all correct answers)

Indentation before the code. (*)


Blank lines in the code. (*)
Space in the print statements.
Space between words. (*)
Space between the [ ] braces.
Correct
(1/1) Points
3. Java mostly reads code line-by-line.
True (*)
False
Correct
(1/1) Points
4. Which of the following three statements are true about breakpoint?
(Choose all correct answers)

They insert break statements.


They can be used to check the current state of the program (*)
They abruptly ends the code execution.
They pause code execution. (*)
They help with debugging. (*)
Correct
(1/1) Points
5. You can set any number of breakpoints for your program.
True (*)
False
Correct
6. Code within curly braces is called a “Block of code”.
True (*)
False
Correct
(1/1) Points
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(){


System.out.println("Employee Salary: "+salary);
}
}
name
empId
salary
displaySalary() (*)
Correct
(1/1) Points
8. In object oriented programming, there is an emphasis on which of the following
two:
(Choose all correct answers)

Creation of procedures.
Modeling objects. (*)
Writing algorithms.
Object interaction without a prescribed order. (*)
Correct
(1/1) Points
9. An object may interact with another object by invoking methods.
True (*)
False
Correct
(1/1) Points
10. 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.
True (*)
False
Correct
11. There are several fields and methods in a Shirt class. Which of the following
could be a method in the Shirt class?
size
price
getShirtSize() (*)
color
Correct
(1/1) Points
12. A software feature may allow the user to perform a specific task.
True (*)
False
Correct
(1/1) Points
13. What is the correct order of steps in the Spiral Model of Development?
Design, Develop , Requirements, Test
Design, Requirements, Develop, Test
Requirements, Design, Test, Develop
Requirements, Design, Develop, Test (*)
Correct
(1/1) Points
14. You’d like to see a movie with a few friends. You write an email to confirm plans.

Hi Friends,
There’s a new movie “Attack of the Duke!” premiering this Friday at Oracle Cinema
at 4:30 PM. The cinema is at the corner of South Street and Walnut Ave. Subway
would be the best way to get there.

Would any of you be interested in going?

Which of the following are requirements for this plan?


Travel via subway.
Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30 PM. (*)
Reach the cinema by 4:00 PM.
Double check the location by verifying you’re on South Street and Walnut Ave.
Correct
(1/1) Points
15. Which of the following are adequate definitions for components of the Spiral
Model of Development?
(Choose all correct answers)

Design: Plan the approach (*)


Test: Run the code and verify results (*)
Requirements: Start the development
Develop: Collect all specified instructions
Correct

Section 3 Quiz 2 - L3-L5


(Answer all questions in this section)
1. Which two statements are true about the Scanner class?
(Choose all correct answers)

A Scanner’s delimiter can be changed. (*)


A Scanner object opens a stream for collecting input. (*)
A Scanner object doesn’t have fields and methods.
Scanners cannot read text files.
Correct
(1/1) Points
2. 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/1) Points
3. System.in readies Scanner to collect input from the console.
True (*)
False
Correct
(1/1) Points
4. A short data type can be promoted to which of the following types?
(Choose all correct answers)

long (*)
int (*)
double (*)
boolean
byte
Correct
(1/1) Points
5. What is the correct way to cast a long to an int?
int longToInt = (int)20L; (*)
int longToInt = int 20L;
int longToInt = 20L(int);
int longToInt = 20L;
Correct
6. Which exception occurs because a String cannot be parsed as an int?
NumberFormatException (*)
ArithmeticException
NullPointerException
ValueNotFoundException
Correct
(1/1) Points
7. Automatic promotion from smaller data type to a larger data type is not allowed
in Java.
True
False (*)
Correct
(1/1) Points
8. A double with the value of 20.5 is cast to an int. What is the value of the int?
20 (*)
21
20.5
25
Correct
(1/1) Points
9. Which two statements are true about type casting?
(Choose all correct answers)

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


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.
Correct
(1/1) Points
10. An Object cannot have String objects as properties.
True
False (*)
Correct
11. A String can be created by combining multiple String Literals.
True (*)
False
Correct
(1/1) Points
12. Char data types cannot handle multiple characters.
True (*)
False
Correct
(1/1) Points
13. Which two statements are true about String concatenation.
(Choose all correct answers)

Strings can be combined using the ‘+’ operator (*)


String concatenation cannot be done with numbers.
String concatenation can be done with String variables and String Literals. (*)
String concatenation cannot be done with more than two String Literals.
Correct
(1/1) Points
14. In Java, char is a primitive data type, while String is an object data type.
True (*)
False
Correct
(1/1) Points
15. Given the expression:

String message = "Hello World";

Which is the String Literal?


String message
Hello World (*)
message
String message = "Hello World";
Correct
Section 4 Quiz 2 - L3-L5
(Answer all questions in this section)
1. 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
(1/1) Points
2. Which values are returned by the method nextBoolean();
Nothing is returned.
Either a true or false. (*)
Returns the next value.
An integer value.
Correct
(1/1) Points
3. You need to generate random integer values between 0 and 80 (inclusive). Which
statement should you use?
nextInt(0-79);
nextInt(80);
nextInt(81); (*)
nextInt();
Correct
(1/1) Points
4. Which class is used to generate random numbers?
Number
Random (*)
Integer
Double
Correct
(1/1) Points
5. Every method of the Math class returns a numerical result.
True (*)
False
Correct
6. Which two are the features of the Math class?
(Choose all correct answers)

Common math functions like square root are taken care of in the language. (*)
Math methods can be invoked with Strings as arguments.
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
7. All the methods in the Math class are static methods.
True (*)
False
Correct
(1/1) Points
8. A constant field, like Math.PI is used to represent a fixed value.
True (*)
False
Correct
(1/1) Points
9. Which method returns the length of a String?
compareTo()
charAt()
findLength ()
length() (*)
Correct
(1/1) Points
10. What is the output?

public static void main(String args[]) {


String greeting = "Java World!";
String w = greeting.substring(7, 11);
System.out.println(w);
}
ld!
rld
orld!
rld! (*)
Correct
11. String objects are immutable.
True (*)
False
Correct
(1/1) Points
12. A String is a sequence characters.
True (*)
False
Correct
(1/1) Points
13. 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
Compilation error.
Java World! + 8
Correct
(1/1) Points
14. The indexOf() method returns the index value of a character in the string.
True (*)
False
Correct
(1/1) Points
15. 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

You might also like