100% found this document useful (16 votes)
37 views

Download Study Resources for Test Bank for Intro to Java Programming, Comp Version, 10/E 10th Edition : 0133813460

The document provides links to various test banks and solution manuals for Java programming and other subjects, including detailed descriptions of each product. It also includes a Java code snippet that calculates the average of three numbers and various multiple-choice questions related to Java programming concepts. Additionally, it covers topics such as variable naming conventions, numeric data types, and the use of operators in Java.

Uploaded by

sayestommy52
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (16 votes)
37 views

Download Study Resources for Test Bank for Intro to Java Programming, Comp Version, 10/E 10th Edition : 0133813460

The document provides links to various test banks and solution manuals for Java programming and other subjects, including detailed descriptions of each product. It also includes a Java code snippet that calculates the average of three numbers and various multiple-choice questions related to Java programming concepts. Additionally, it covers topics such as variable naming conventions, numeric data types, and the use of operators in Java.

Uploaded by

sayestommy52
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Visit https://testbankmall.

com to download the full version and


explore more testbank or solution manual

Test Bank for Intro to Java Programming, Comp


Version, 10/E 10th Edition : 0133813460

_____ Click the link below to download _____


https://testbankmall.com/product/test-bank-for-intro-
to-java-programming-comp-version-10-e-10th-
edition-0133813460/

Explore and download more testbank at testbankmall.com


Here are some suggested products you might be interested in.
Click the link to download

Solution Manual for Intro to Java Programming, Comp


Version, 10/E 10th Edition : 0133813460

https://testbankmall.com/product/solution-manual-for-intro-to-java-
programming-comp-version-10-e-10th-edition-0133813460/

Introduction to Java Programming Comprehensive Version


10th Edition Liang Test Bank

https://testbankmall.com/product/introduction-to-java-programming-
comprehensive-version-10th-edition-liang-test-bank/

Test Bank for Introduction to Java Programming,


Comprehensive Version, 9/E 9th Edition : 0133050572

https://testbankmall.com/product/test-bank-for-introduction-to-java-
programming-comprehensive-version-9-e-9th-edition-0133050572/

Test Bank for Principles of Life 2nd Edition Hillis

https://testbankmall.com/product/test-bank-for-principles-of-life-2nd-
edition-hillis/
Test Bank for Precalculus, 11th Edition, Sullivan

https://testbankmall.com/product/test-bank-for-precalculus-11th-
edition-sullivan/

Understanding Nutrition Whitney 13th Edition Solutions


Manual

https://testbankmall.com/product/understanding-nutrition-whitney-13th-
edition-solutions-manual/

Test Bank for Essentials of Economics The Mcgraw Hill


Series Economics 9th Edition Bradley Schiller

https://testbankmall.com/product/test-bank-for-essentials-of-
economics-the-mcgraw-hill-series-economics-9th-edition-bradley-
schiller/

Test Bank for Criminal Procedure for the Criminal Justice


Professional, 11th Edition, John N. Ferdico, Henry F.
Fradella, Christopher Totten
https://testbankmall.com/product/test-bank-for-criminal-procedure-for-
the-criminal-justice-professional-11th-edition-john-n-ferdico-henry-f-
fradella-christopher-totten/

Solution Manual for Strategic Management: Theory & Cases:


An Integrated Approach, 13th Edition, Charles W. L. Hill,
Melissa A. Schilling Gareth R. Jones
https://testbankmall.com/product/solution-manual-for-strategic-
management-theory-cases-an-integrated-approach-13th-edition-charles-w-
l-hill-melissa-a-schilling-gareth-r-jones/
Test Bank for Calculus for Business, Economics, Life
Sciences, and Social Sciences, Brief Version, 14th
Edition, Raymond A. Barnett, Michael R. Ziegler Karl E.
Byleen Christopher J. Stocker
https://testbankmall.com/product/test-bank-for-calculus-for-business-
economics-life-sciences-and-social-sciences-brief-version-14th-
edition-raymond-a-barnett-michael-r-ziegler-karl-e-byleen-christopher-
j-stocker/
import java.util.Scanner; chapter2.txt

public class Test1 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");

Page 2
chapter2.txt
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();

// Compute average
double average = (number1 + number2 + number3) / 3;

// Display result
System.out.println(average);
}
}

a. 1.0
b. 2.0
c. 3.0
d. 4.0
Key:b

#
4. What is the exact output of the following code?

double area = 3.5;


System.out.print("area");
System.out.print(area);

a. 3.53.5
b. 3.5 3.5
c. area3.5
d. area 3.5
Key:c

#
Section 2.4 Identifiers
4. Every letter in a Java keyword is in lowercase?
a. true
b. false
Key:a

#
5. Which of the following is a valid identifier?
a. $343
b. class
c. 9X
d. 8+9
e. radius
Key:ae

Page 3
chapter2.txt
Section 2.5 Variables
6. Which of the following are correct names for variables according to Java
naming conventions?
a. radius
b. Radius
c. RADIUS
d. findArea
e. FindArea
Key:ad

#
7. Which of the following are correct ways to declare variables?
a. int length; int width;
b. int length, width;
c. int length; width;
d. int length, int width;
Key:ab

#
Section 2.6 Assignment Statements and Assignment Expressions
8. is the Java assignment operator.
a. ==
b. :=
c. =
d. =:
Key:c

#
9. To assign a value 1 to variable x, you write
a. 1 = x;
b. x = 1;
c. x := 1;
d. 1 := x;
e. x == 1;
Key:b

#
10. Which of the following assignment statements is incorrect?
a. i = j = k = 1;
b. i = 1; j = 1; k = 1;
c. i = 1 = j = 1 = k = 1;
d. i == j == k == 1;
Key:cd

#
Section 2.7 Named Constants
11. To declare a constant MAX_LENGTH inside a method with value 99.98, you write
a. final MAX_LENGTH = 99.98;
Page 4
chapter2.txt
b. final float MAX_LENGTH = 99.98;
c. double MAX_LENGTH = 99.98;
d. final double MAX_LENGTH = 99.98;
Key:d

#
12. Which of the following is a constant, according to Java naming conventions?
a. MAX_VALUE
b. Test
c. read
d. ReadInt
e. COUNT
Key:ae

#
13. To improve readability and maintainability, you should declare
instead of using literal values such as 3.14159.
a. variables
b. methods
c. constants
d. classes
Key:c

#
Section 2.8 Naming Conventions
60. According to Java naming convention, which of the following names can be
variables?
a. FindArea
b. findArea
c. totalLength
d. TOTAL_LENGTH
e. class
Key:bc

#
Section 2.9 Numeric Data Types and Operations
14. Which of these data types requires the most amount of memory?
a. long
b. int
c. short
d. byte
Key:a

#
34. If a number is too large to be stored in a variable of the float type, it
.
a. causes overflow
b. causes underflow

Page 5
chapter2.txt
c. causes no error
d. cannot happen in Java
Key:a

#
15. Analyze the following code:

public class Test {


public static void main(String[] args) {
int n = 10000 * 10000 * 10000;
System.out.println("n is " + n);
}
}
a. The program displays n is 1000000000000
b. The result of 10000 * 10000 * 10000 is too large to be stored in an int
variable n. This causes an overflow and the program is aborted.
c. The result of 10000 * 10000 * 10000 is too large to be stored in an int
variable n. This causes an overflow and the program continues to execute because
Java does not report errors on overflow.
d. The result of 10000 * 10000 * 10000 is too large to be stored in an int
variable n. This causes an underflow and the program is aborted.
e. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable
n. This causes an underflow and the program continues to execute because Java does
not report errors on underflow.
Key:c

#
16. What is the result of 45 / 4?
a. 10
b. 11
c. 11.25
d. 12
Key:b 45 / 4 is an integer division, which results in 11

#
18. Which of the following expression results in a value 1?
a. 2 % 1
b. 15 % 4
c. 25 % 5
d. 37 % 6
Key:d 2 % 1 is 0, 15 % 4 is 3, 25 % 5 is 0, and 37 % 6 is 1

#
19. 25 % 1 is
a. 1
b. 2
c. 3
d. 4

Page 6
chapter2.txt
e. 0
Key:e

#
20. -25 % 5 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:e

#
21. 24 % 5 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:d

#
22. -24 % 5 is
a. -1
b. -2
c. -3
d. -4
e. 0
Key:d

#
23. -24 % -5 is
a. 3
b. -3
c. 4
d. -4
e. 0
Key:d

#
30. Math.pow(2, 3) returns .
a. 9
b. 8
c. 9.0
d. 8.0
Key:d It returns a double value 8.0.

Page 7
chapter2.txt
30. Math.pow(4, 1 / 2) returns .
a. 2
b. 2.0
c. 0
d. 1.0
e. 1
Key:d Note that 1 / 2 is 0.

#
30. Math.pow(4, 1.0 / 2) returns .
a. 2
b. 2.0
c. 0
d. 1.0
e. 1
Key:b Note that the pow method returns a double value, not an integer.
#
31. The method returns a raised to the power of b.

a. Math.power(a, b)
b. Math.exponent(a, b)
c. Math.pow(a, b)
d. Math.pow(b, a)
Key:c

#
Section 2.10 Numeric Literals
15. To declare an int variable number with initial value 2, you write
a. int number = 2L;
b. int number = 2l;
c. int number = 2;
d. int number = 2.0;
Key:c

#
32. Analyze the following code.

public class Test {


public static void main(String[] args) {
int month = 09;
System.out.println("month is " + month);
}
}
a. The program displays month is 09
b. The program displays month is 9
c. The program displays month is 9.0
d. The program has a syntax error, because 09 is an incorrect literal value.
Key:d Any numeric literal with the prefix 0 is an octal value. But 9 is not an octal

Page 8
chapter2.txt
digit. An octal digit is 0, 1, 2, 3, 4, 5, 6, or 7.

#
15. Which of the following are the same as 1545.534?
a. 1.545534e+3
b. 0.1545534e+4
c. 1545534.0e-3
d. 154553.4e-2
Key:abcd

#
Section 2.11 Evaluating Expressions and Operator Precedence
24. The expression 4 + 20 / (3 - 1) * 2 is evaluated to
a. 4
b. 20
c. 24
d. 9
e. 25
Key:c

#
Section 2.12 Case Study: Displaying the Current Time
58. The System.currentTimeMillis() returns .
a. the current time.
b. the current time in milliseconds.
c. the current time in milliseconds since midnight.
d. the current time in milliseconds since midnight, January 1, 1970.
e. the current time in milliseconds since midnight, January 1, 1970 GMT (the
Unix time).
Key:e

#
24. To obtain the current second, use .
a. System.currentTimeMillis() % 3600
b. System.currentTimeMillis() % 60
c. System.currentTimeMillis() / 1000 % 60
d. System.currentTimeMillis() / 1000 / 60 % 60
e. System.currentTimeMillis() / 1000 / 60 / 60 % 24
Key:c

#
24. To obtain the current minute, use .
a. System.currentTimeMillis() % 3600
b. System.currentTimeMillis() % 60
c. System.currentTimeMillis() / 1000 % 60
d. System.currentTimeMillis() / 1000 / 60 % 60
e. System.currentTimeMillis() / 1000 / 60 / 60 % 24
Key:d

Page 9
chapter2.txt

#
24. To obtain the current hour in UTC, use _.
a. System.currentTimeMillis() % 3600
b. System.currentTimeMillis() % 60
c. System.currentTimeMillis() / 1000 % 60
d. System.currentTimeMillis() / 1000 / 60 % 60
e. System.currentTimeMillis() / 1000 / 60 / 60 % 24
Key:e

#
Section 2.13 Augmented Assignment Operators
24. To add a value 1 to variable x, you write
a. 1 + x = x;
b. x += 1;
c. x := 1;
d. x = x + 1;
e. x = 1 + x;
Key:bde

#
25. To add number to sum, you write (Note: Java is case-sensitive)
a. number += sum;
b. number = sum + number;
c. sum = Number + sum;
d. sum += number;
e. sum = sum + number;
Key:de

#
26. Suppose x is 1. What is x after x += 2?
a. 0
b. 1
c. 2
d. 3
e. 4
Key:d

#
27. Suppose x is 1. What is x after x -= 1?
a. 0
b. 1
c. 2
d. -1
e. -2
Key:a

Page 10
chapter2.txt
28. What is x after the following statements?

int x = 2;
int y = 1;
x *= y + 1;

a. x is 1.
b. x is 2.
c. x is 3.
d. x is 4.
Key:d

#
29. What is x after the following statements?

int x = 1;
x *= x + 1;

a. x is 1.
b. x is 2.
c. x is 3.
d. x is 4.
Key:b

#
29. Which of the following statements are the same?

(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)

a. (A) and (B) are the same


b. (A) and (C) are the same
c. (B) and (C) are the same
d. (A), (B), and (C) are the same
Key:a

#
Section 2.14 Increment and Decrement Operators
21. Are the following four statements equivalent?
number += 1;
number = number + 1;
number++;
++number;
a. Yes
b. No
Key:a

Page 11
chapter2.txt
#
34. What is i printed?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = ++j + j * 5;

System.out.println("What is i? " + i);


}
}
a. 0
b. 1
c. 5
d. 6
Key:d Operands are evaluated from left to right in Java. The left-hand operand of a
binary operator is evaluated before any part of the right-hand operand is evaluated.
This rule takes precedence over any other rules that govern expressions. Therefore,
++j is evaluated first, and returns 1. Then j*5 is evaluated, returns 5.

#
35. What is i printed in the following code?

public class Test {


public static void main(String[] args) {
int j = 0;
int i = j++ + j * 5;

System.out.println("What is i? " + i);


}
}
a. 0
b. 1
c. 5
d. 6
Key:c Same as before, except that j++ evaluates to 0.

#
36. What is y displayed in the following code?

public class Test {


public static void main(String[] args) {
int x = 1;
int y = x++ + x;
System.out.println("y is " + y);
}
}
a. y is 1.
b. y is 2.

Page 12
chapter2.txt
c. y is 3.
d. y is 4.
Key:c When evaluating x++ + x, x++ is evaluated first, which does two things: 1.
returns 1 since it is post-increment. x becomes 2. Therefore y is 1 + 2.

#
37. What is y displayed?

public class Test {


public static void main(String[] args) {
int x = 1;
int y = x + x++;
System.out.println("y is " + y);
}
}
a. y is 1.
b. y is 2.
c. y is 3.
d. y is 4.
Key:b When evaluating x + x++, x is evaluated first, which is 1. X++ returns 1 since
it is post-increment and 2. Therefore y is 1 + 1.

#
Section 2.15 Numeric Type Conversions
38. To assign a double variable d to a float variable x, you write
a. x = (long)d
b. x = (int)d;
c. x = d;
d. x = (float)d;
Key:d

#
17. Which of the following expressions will yield 0.5?
a. 1 / 2
b. 1.0 / 2
c. (double) (1 / 2)
d. (double) 1 / 2
e. 1 / 2.0
Key:bde 1 / 2 is an integer division, which results in 0.

#
39. What is the printout of the following code:

double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);
a. x is 5 and y is 6
b. x is 6.0 and y is 6.0

Page 13
chapter2.txt
c. x is 6 and y is 6
d. x is 5.5 and y is 5
e. x is 5.5 and y is 5.0
Key:d The value is x is not changed after the casting.

#
40. Which of the following assignment statements is illegal?
a. float f = -34;
b. int t = 23;
c. short s = 10;
d. int t = (int)false;
e. int t = 4.5;
Key:de

#
41. What is the value of (double)5/2?
a. 2
b. 2.5
c. 3
d. 2.0
e. 3.0
Key:b

#
42. What is the value of (double)(5/2)?
a. 2
b. 2.5
c. 3
d. 2.0
e. 3.0
Key:d

#
43. Which of the following expression results in 45.37?
a. (int)(45.378 * 100) / 100
b. (int)(45.378 * 100) / 100.0
c. (int)(45.378 * 100 / 100)
d. (int)(45.378) * 100 / 100.0
Key:b

#
43. The expression (int)(76.0252175 * 100) / 100 evaluates to .
a. 76.02
b. 76
c. 76.0252175
d. 76.03
Key:b In order to obtain 76.02, you have divide 100.0.

Page 14
chapter2.txt
#
44. If you attempt to add an int, a byte, a long, and a double, the result will
be a value.
a. byte
b. int
c. long
d. double
Key:d

#
Section 2.16 Software Life Cycle
1. is a formal process that seeks to understand the problem and

document in detail what the software system needs to do.


a. Requirements specification
b. Analysis
c. Design
d. Implementation
e. Testing
Key:a
#
1. System analysis seeks to analyze the data flow and to identify the

system’s input and output. When you do analysis, it helps to identify what the
output is first, and then figure out what input data you need in order to produce
the output.
a. Requirements specification
b. Analysis
c. Design
d. Implementation
e. Testing
Key:b

#
0. Any assignment statement can be used as an assignment expression.
a. true
b. false
Key:a

#
1. You can define a constant twice in a block.
a. true
b. false
Key:b
#
44. are valid Java identifiers.
a. $Java
b. _RE4
Page 15
chapter2.txt
c. 3ere
d. 4+4
e. int
Key:ab

#
2. You can define a variable twice in a block.
a. true
b. false
Key:b

#
3. The value of a variable can be changed.
a. true
b. false
Key:a

#
4. The result of an integer division is the integer part of the division; the
fraction part is truncated.
a. true
b. false
Key:a

#
5. You can always assign a value of int type to a variable of long type without
loss of information.
a. true
b. false
Key:a

#
6. You can always assign a value of long type to a variable of int type without
loss of precision.
a. true
b. false
Key:b

#
13. A variable may be assigned a value only once in the program.
a. true
b. false
Key:b

#
14. You can change the value of a constant.
a. true
b. false

Page 16
chapter2.txt
Key:b

#
2. To declare a constant PI, you write
a. final static PI = 3.14159;
b. final float PI = 3.14159;
c. static double PI = 3.14159;
d. final double PI = 3.14159;
Key:d

#
3. To declare an int variable x with initial value 200, you write
a. int x = 200L;
b. int x = 200l;
c. int x = 200;
d. int x = 200.0;
Key:c

#
4. To assign a double variable d to an int variable x, you write
a. x = (long)d
b. x = (int)d;
c. x = d;
d. x = (float)d;
Key:b

#
8. Which of the following is a constant, according to Java naming conventions?
a. MAX_VALUE
b. Test
c. read
d. ReadInt
Key:a

#
9. Which of the following assignment statements is illegal?
a. float f = -34;
b. int t = 23;
c. short s = 10;
d. float f = 34.0;
Key:d

#
10. A Java statement ends with a .
a. comma (,)
b. semicolon (;)
c. period (.)
d. closing brace

Page 17
chapter2.txt
Key:b

#
11. The assignment operator in Java is .
a. :=
b. =
c. = =
d. <-
Key:b

#
12. Which of these data types requires the least amount of memory?
a. float
b. double
c. short
d. byte
Key:d

#
13. Which of the following operators has the highest precedence?
a. casting
b. +
c. *
d. /
Key:a

#
17. If you attempt to add an int, a byte, a long, and a float, the result will
be a value.
a. float
b. int
c. long
d. double
Key:a

#
18. If a program compiles fine, but it terminates abnormally at runtime, then
the program suffers .
a. a syntax error
b. a runtime error
c. a logic error
Key:b

#
24. What is 1 % 2?
a. 0
b. 1
c. 2
Page 18
chapter2.txt
Key:b

#
26. What is the printout of the following code:

double x = 10.1;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

a. x is 10 and y is 10
b. x is 10.0 and y is 10.0
c. x is 11 and y is 11
d. x is 10.1 and y is 10
e. x is 10.1 and y is 10.0
Key:d

#
32. The compiler checks .
a. syntax errors
b. logical errors
c. runtime errors
Key:a

#
33. You can cast a double value to _.
a. byte
b. short
c. int
d. long
e. float
Key:abcde
#
34. The keyword must be used to declare a constant.
a. const
b. final
c. static
d. double
e. int
Key:b

#
37. pow is a method in the class.
a. Integer
b. Double
c. Math
d. System
Key:c

Page 19
chapter2.txt
#
38. currentTimeMills is a method in the class.
a. Integer
b. Double
c. Math
d. System
Key:d

#
39. 5 % 1 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:e

#
40. 5 % 2 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:a

#
41. 5 % 3 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:b

#
42. 5 % 4 is
a. 1
b. 2
c. 3
d. 4
e. 0
Key:a

#
43. 5 % 5 is
a. 1

Page 20
chapter2.txt
b. 2
c. 3
d. 4
e. 0
Key:e

#
43. -5 % 5 is
a. -1
b. -2
c. -3
d. -4
e. 0
Key:e

#
43. -15 % 4 is
a. -1
b. -2
c. -3
d. -4
e. 0
Key:c

#
43. -15 % -4 is
a. -1
b. -2
c. -3
d. -4
e. 0
Key:c

#
43. A variable must be declared before it can be used.
a. True
b. False
Key:a

#
43. A constant can be defined using using the final keyword.
a. True
b. False
Key:a

#
43. Which of the following are not valid assignment statements?
a. x = 55;

Page 21
chapter2.txt
b. x = 56 + y;
c. 55 = x;
d. x += 3;
Key:c

Page 22
Sample Final Exam for CSCI 1302

FINAL EXAM AND COURSE OUTCOMES MATCHING


COURSE OUTCOMES
Upon successful completion of this course, students should be able to
1. understand OO concepts: encapsulation, inheritance, polymorphism, interfaces,
abstract classes
2. use Unified Modeling Language for design, analysis, and documentation
3. develop graphical user interfaces
4. develop event-driven programs
5. use file I/O and handle exceptions
6. design and implement OO programs

Here is a mapping of the final comprehensive exam against the course outcomes:

Question Matches outcomes


1 1
2 2
3 3, 4, 5
4 6, 7
5 1, 2, 3, 4, 5, 6, 7

1
Name: CSCI 1302 Introduction to Programming
Covers chs8-19 Armstrong Atlantic State University
Final Exam Instructor: Dr. Y. Daniel Liang

Please note that the university policy prohibits giving the exam score by email. If you need to know your
final exam score, come to see me during my office hours next semester.

I pledge by honor that I will not discuss the contents of this exam with
anyone.
Signed by Date

1. Design and implement classes. (10 pts)

Design a class named Person and its two subclasses named Student and
Employee. Make Faculty and Staff subclasses of Employee. A person has a
name, address, phone number, and email address. A student has a class
status (freshman, sophomore, junior, or senior). Define the status as a
constant. An employee has an office, salary, and date hired. Define a
class named MyDate that contains the fields year, month, and day. A
faculty member has office hours and a rank. A staff member has a title.
Override the toString method in each class to display the class name
and the person's name.

Draw the UML diagram for the classes. Write the code for the Student
class only.

2
2. Design and use interfaces (10 pts)

Write a class named Octagon that extends GeometricObject


and implements the Comparable and Cloneable interfaces.
Assume that all eight sides of the octagon are of equal
size. The area can be computed using the following formula:
area  (2  4 / 2) * side * side

Draw the UML diagram that involves Octagon,


GeometricObject, Comparable, and Cloneable.

3
3. Design and create GUI applications (10 pts)

Write a Java applet to add two numbers from text fields, and
displays the result in a non-editable text field. Enable your applet
to run standalone with a main method. A sample run of the applet is
shown in the following figure.

4
4. Text I/O (10 pts)

Write a program that will count the number of characters (excluding


control characters '\r' and '\n'), words, and lines, in a file. Words
are separated by spaces, tabs, carriage return, or line-feed
characters. The file name should be passed as a command-line argument,
as shown in the following sample run.

5
5. Multiple Choice Questions: (1 pts each)
(1. Mark your answers on the sheet. 2. Login and click Take
Instructor Assigned Quiz for QFinal. 3. Submit it online
within 5 mins. 4. Close the Internet browser.)
1. describes the state of an object.

a. data fields
b. methods
c. constructors
d. none of the above

#
2. An attribute that is shared by all objects of the class is coded
using .
a. an instance variable
b. a static variable
c. an instance method
d. a static method

#
3. If a class named Student has no constructors defined explicitly,
the following constructor is implicitly provided.

a. public Student()
b. protected Student()
c. private Student()
d. Student()

#
4. If a class named Student has a constructor Student(String name)
defined explicitly, the following constructor is implicitly provided.

a. public Student()
b. protected Student()
c. private Student()
d. Student()
e. None

#
5. Suppose the xMethod() is invoked in the following constructor in
a class, xMethod() is in the class.

public MyClass() {
xMethod();
}

a. a static method
b. an instance method
c. a static method or an instance method

#
6. Suppose the xMethod() is invoked from a main method in a class as
follows, xMethod() is in the class.

public static void main(String[] args) {

6
xMethod();
}

a. a static method
b. an instance method
c. a static or an instance method

#
7. What would be the result of attempting to compile and
run the following code?
public class Test {
static int x;

public static void main(String[] args){


System.out.println("Value is " + x);
}
}

a. The output "Value is 0" is printed.


b. An "illegal array declaration syntax" compiler error occurs.
c. A "possible reference before assignment" compiler error occurs.
d. A runtime error occurs, because x is not initialized.

#
8. Analyze the following code:

public class Test {


private int t;

public static void main(String[] args) {


Test test = new Test();
System.out.println(test.t);
}
}

a. The variable t is not initialized and therefore causes errors.


b. The variable t is private and therefore cannot be accessed in the
main method.
c. Since t is an instance variable, it cannot appear in the static
main method.
d. The program compiles and runs fine.

#
9. Suppose s is a string with the value "java". What will be
assigned to x if you execute the following code?

char x = s.charAt(4);

a. 'a'
b. 'v'
c. Nothing will be assigned to x, because the execution causes the
runtime error StringIndexOutofBoundsException.
d. None of the above.

#
10. What is the printout for the following code?

class Test {

7
public static void main(String[] args) {
int[] x = new int[3];
System.out.println("x[0] is "+x[0]);
}
}

a. The program has a syntax error because the size of the array
wasn't specified when declaring the array.
b. The program has a runtime error because the array elements are
not initialized.
c. The program runs fine and displays x[0] is 0.
d. None of the above.

#
11. How can you get the word "abc" in the main method from the
following call?

java Test "+" 3 "abc" 2

a. args[0]
b. args[1]
c. args[2]
d. args[3]

#
12. Which code fragment would correctly identify the number of
arguments passed via the command line to a Java application,
excluding the name of the class that is being invoked?

a. int count = args.length;


b. int count = args.length - 1;
c. int count = 0; while (args[count] != null) count ++;
d. int count=0; while (!(args[count].equals(""))) count ++;

#
13. Show the output of running the class Test in the following code
lines:

interface A {
void print();
}

class C {}

class B extends C implements A {


public void print() { }
}

class Test {
public static void main(String[] args) {
B b = new B();
if (b instanceof A)
System.out.println("b is an instance of A");
if (b instanceof C)
System.out.println("b is an instance of C");
}
}

8
a. Nothing.
b. b is an instance of A.
c. b is an instance of C.
d. b is an instance of A followed by b is an instance of C.

#
14. When you implement a method that is defined in a superclass, you
the original method.
a. overload
b. override
c. copy
d. call

#
15. What modifier should you use on a variable so that it can only be
referenced inside its defining class.
a. public
b. private
c. protected
d. Use the default modifier.

#
16. What is the output of running class C?

class A {
public A() {
System.out.println(
"The default constructor of A is invoked");
}
}

class B extends A {
public B() {
System.out.println(
"The default constructor of B is invoked");
}
}

public class C {
public static void main(String[] args) {
B b = new B();
}
}

a. none
b. "The default constructor of B is invoked"
c. "The default constructor of A is invoked" followed by "The
default constructor of B is invoked"
d. "The default constructor of A is invoked"

#
17. Analyze the following program.

class Test {

9
public static void main(String[] args) {
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormatException

int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
}
catch (Exception ex) {
System.out.println(ex);
}
}
}
a. An exception is raised due to Integer.parseInt(s);
b. An exception is raised due to 2 / i;
c. The program has a compilation error.
d. The program compiles and runs without exceptions.

#
18. What is displayed on the console when running the following
program?

class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java");
int i = 0; int y = 2/i;
System.out.println("Welcome to Java");
}
catch (RuntimeException ex) {
System.out.println("Welcome to Java");
}
finally {
System.out.println("End of the block");
}
}
}
a. The program displays Welcome to Java three times followed by End
of the block.
b. The program displays Welcome to Java two times followed by End of
the block.
c. The program displays Welcome to Java three times.
d. The program displays Welcome to Java two times.
#
19. To append data to an existing file, use to construct a
FileOutputStream for file out.dat.
a. new FileOutputStream("out.dat")
b. new FileOutputStream("out.dat", false)
c. new FileOutputStream("out.dat", true)
d. new FileOutputStream(true, "out.dat")

10
#
20. After the following program is finished, how many bytes are written to the
file t.dat?

import java.io.*;

public class Test {


public static void main(String[] args) throws IOException {
DataOutputStream output = new DataOutputStream(
new FileOutputStream("t.dat"));
output.writeShort(1234);
output.writeShort(5678);
output.close();
}
}
a. 2 bytes.
b. 4 bytes.
c. 8 bytes.
d. 16 bytes.

Have you submitted your answer to LiveLib?

11
Discovering Diverse Content Through
Random Scribd Documents
I waive the crime, and speak of the facts from a disinterested
stand-point. I have been such a diligent scholar in the severe school
of experience, that I have learned to look upon my own misfortunes
lightly, and certainly can behold—with an unmoistened eye—my
neighbor’s choicest sticks noiselessly slipping into an adjoining yard.
Besides, my neighbor can afford to lose a few. To make my position
good, I entrench myself behind the following fact: To be in the
fashion, he pays the price of a good-sized farm for seats at the opera,
where the language is as foreign to his understanding as South Sea
Island gibberish. While he indifferently beholds such a wasteful
running at the bung, why should I assume the busybody’s rôle and
clap my finger on the dripping spigot?
Besides, I saw his wife last evening with fully four yards of
expensive satin trailing in the dust. It was my misfortune to be
walking directly behind her. As the crowd was pressing me onward, I
was obliged to dance a sailor’s hornpipe around the hall, in order to
keep from treading upon her skirts. It needed not the grins of
lookers-on to assure me that I was cutting a ridiculous figure.
I am now enjoying my revenge! Indirectly though it comes, it is
none the less sweet or acceptable. On the contrary, it is rather more
gratifying, as it calls for no action on my part, but simply to keep my
mouth hermetically sealed. The poet truly sings:—
“Time at last sets all things even.”

It has been in this case much quicker than I expected. As the


skinny white arm stretches up out of the gloom of the
washerwoman’s yard, and another billet shoots from the pile and
disappears like a star from the firmament of heaven, I feel that a load
is lifted from my heart, and I am reaping revenge.
Stay! what is this? a note, that all the evening escaped my notice.
Lo! an aroma issues from it, sweet as Cytherea’s breath! It is an
invitation, as I live, to help dissect a Christmas turkey! Sound the
timbrel, beat the tom-tom. I am not forgotten yet!
TRANSCRIBER’S NOTES
1. P. 319, changed “shovin’ of it” to “shovin’ all of it”.
2. Silently corrected typographical errors and variations in
spelling.
3. Archaic, non-standard, and uncertain spellings retained
as printed.
4. Footnotes were re-indexed using numbers and collected
together at the end of the chapter.
*** END OF THE PROJECT GUTENBERG EBOOK FRONTIER HUMOR
IN VERSE, PROSE AND PICTURE ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

testbankmall.com

You might also like