100% found this document useful (1 vote)
881 views10 pages

Java Middle Exam Answers

The document summarizes the results of a Java Foundations midterm exam, including 20 multiple choice questions across 3 sections. An asterisk indicates the correct answer for each question. The exam covers topics like identifying methods in code, defining components of the Spiral Model of development, data type promotions, parsing, and statements about the Scanner class.

Uploaded by

harshitha
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
100% found this document useful (1 vote)
881 views10 pages

Java Middle Exam Answers

The document summarizes the results of a Java Foundations midterm exam, including 20 multiple choice questions across 3 sections. An asterisk indicates the correct answer for each question. The exam covers topics like identifying methods in code, defining components of the Spiral Model of development, data type promotions, parsing, and statements about the Scanner class.

Uploaded by

harshitha
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/ 10

Test: 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. In the code example below, identify any methods:


Mark for Review
public class Employee { (1) Points
public String name = " Duke";
public int empId = 12105;
public float salary;

public void displaySalary(){


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

name
displaySalary() (*)
salary
empId

Correct

2. There are several fields and methods in a Shirt class. Which of the following could be a
Mark for Review
method in the Shirt class?
(1) Points

getShirtSize() (*)
price
size
color

Correct

3.  You design a Circle class with various fields and methods. Which of the following could
Mark for Review
be fields in this class? Distinguish which of these are between the properties and
behavior. (1) Points

(Choose all correct answers)

radius (*)
calculateDiameter()
color (*)
calculateArea()
calculateCircumference()
Correct

4. Code within curly braces is called a “Block of code”.


Mark for Review
(1) Points

True (*)
False

Correct

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


Mark for Review
(1) Points

True (*)
False

Correct

Page 1 of 10  Next Summary

Test: 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
Mark for Review
again removes the breakpoint.
(1) Points

True (*)
False

Correct

7. Which of the following are adequate definitions for components of the Spiral Model of
Mark for Review
Development?
(1) Points

(Choose all correct answers)

Test: Run the code and verify results (*)


Design: Plan the approach (*)
Develop: Collect all specified instructions
Requirements: Start the development

Correct

8. The Spiral Model reflects an iterative development process.


Mark for Review
(1) Points

True (*)
False

Correct

9.  A software feature may allow the user to perform a specific task.


Mark for Review
(1) Points

True (*)
False

Correct

Section 3
(Answer all questions in this section)

10. The Java compiler automatically promotes byte, short, and chars data type values to int
Mark for Review
data type.
(1) Points

True (*)
False

Correct

Previous Page 2 of 10  Next Summary

Test: 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. What is the correct way to cast a long to an int?


Mark for Review
(1) Points

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


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

Correct

12. What is parsing?


Mark for Review
(1) Points

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

13. What value is assigned to x?


Mark for Review
int x = 25 - 5 * 4 / 2 - 10 + 4; (1) Points

8
9 (*)
34
7

Correct

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


Mark for Review
(1) Points

const
final (*)
static
break 

Correct
15. What is the output? public static void main(String args[]) {
Mark for Review
int x = 100;
int y = x; (1) Points
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

Previous Page 3 of 10  Next Summary

Test: 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)

16. In Java, char is a primitive data type, while String is an object data type.
Mark for Review
(1) Points

True (*)
False

Correct

17.  An Object cannot have String objects as properties.


Mark for Review
(1) Points

True
False (*)

Correct
18. The print() method prints to the console and automatically creates a line.
Mark for Review
(1) Points

True
False (*)

Correct

19. These two code fragments perform the same task.


Mark for Review
 // Fragment 1 (1) Points
String inputString = JOptionPane.showInputDialog("??");
int input = Integer.parseInt(inputString);
input++;

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

True (*)
False

Correct

20. Which two statements are true about the Scanner class?
Mark for Review
(1) Points

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

Incorrect. Refer to Section 3 Lesson 5.

Previous Page 4 of 10  Next Summary

Test: 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. The Scanner class considers space as the default delimiter while reading the input.
Mark for Review
(1) Points

True (*)
False

Correct

22. What is the output?


Mark for Review
public class Hello { (1) Points
public static void main(String args[]) {
String str = ”Hello”;
str = ”World”;
System.out.println(str);
}
}

Hello
Hello World
World (*)
Hello
World

Correct

23. Java is a strongly typed language; therefore you must declare a data type for all
Mark for Review
variables.
(1) Points

True (*)
False

Correct

24. Identify the variable declared in the given code.


Mark for Review
public class Welcome { (1) Points
public static void main(String args[]) {
int a = 2;
System.out.println("a is" + a);
}
}

int
Welcome
a (*)
2

Correct
Section 4
(Answer all questions in this section)

25. The classes of the Java class li brary are organized into packages.
Mark for Review
(1) Points

True (*)
False

Correct

Previous Page 5 of 10  Next Summary

Test: 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)

26. Which two are valid import statements of the Scanner class?
Mark for Review
(1) Points

(Choose all correct answers)

import java.util;
import java.*;
import java.util.*; (*)
import java.util.Scanner; (*)

Correct

27. The import statement consists of two parts.


Mark for Review
import package.className; (1) Points

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

True (*)
False
Correct

28. The JFrame and JOptionPane classes are in th e javax.swing package. Which two will
Mark for Review
import those classes?
(1) Points

(Choose all correct answers)

import javax.swing.*; (*)


import javax.swing;
import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing.J*;

Correct

29. The indexOf() method returns the index value of a character in the string.
Mark for Review
(1) Points

True (*)
False

Correct

30. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
String greeting = "Java World!";
String w = greeting.substring(7, 11);
System.out.println(w);
}

rld! (*)
ld!
orld!
rld

Correct

Previous Page 6 of 10  Next Summary

Test: 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. The String class must be imported u sing java.lang.String;


Mark for Review
(1) Points

True
False (*)

Correct

32. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
String greeting = "Java World!";
String w = greeting.replace("a", "A");
System.out.println(w);
}

JavA World!
JAvA World! (*)
Java World!
JAva World!

Correct

33. Which of the following scenarios would be ideal for writing a method?
Mark for Review
(1) Points

When you don’t find similar lines of code to describe an object’s behavior.
For every five to six lines of code.
To group similar data types t ogether
When you don’t want to repeat similar lines of code to describe an object’s
behavior. (*)

Correct

34.  You’re designing banking software and need to store 10000 customer accounts with
Mark for Review
information on the accountholder’s name, balance, and interest rate. The best
approach is store 30000 separate variables in the main method. (1) Points

True
False (*)

Correct

You might also like