Java (Ch 1 - Ch 7)

Descripción

Computer Science Test sobre Java (Ch 1 - Ch 7), creado por Heather Williams el 23/06/2018.
Heather Williams
Test por Heather Williams, actualizado hace más de 1 año
Heather Williams
Creado por Heather Williams hace casi 6 años
209
0

Resumen del Recurso

Pregunta 1

Pregunta
Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
Respuesta
  • PrintWriter outfile = new PrintWriter("MyFile.txt", true);
  • PrintWriter outfile = new PrintWriter(true, "MyFile.txt");
  • FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter);
  • FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

Pregunta 2

Pregunta
When an object is created, the attributes associated with the object are called
Respuesta
  • instance fields
  • fixed attributes
  • instance methods
  • class instances

Pregunta 3

Pregunta
What will be the value of x after the following code is executed?
Respuesta
  • 110
  • 90
  • 130
  • 210

Pregunta 4

Pregunta
Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?
Respuesta
  • "###.##%"
  • "#0.00%"
  • "##0.0%"
  • "000.0%"

Pregunta 5

Pregunta
Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt?
Respuesta
  • PrintWriter.println("Calvin");
  • diskOut.println("Calvin");
  • System.out.println(diskOut, "Calvin");
  • DiskFile.println("Calvin");

Pregunta 6

Pregunta
What would be the value of discountRate after the following statements are executed?
Respuesta
  • 0.03
  • 0.0
  • 0.01
  • 0.05

Pregunta 7

Pregunta
The ________ is ideal in situations where the exact number of iterations is known.
Respuesta
  • posttest loop
  • while loop
  • do-while loop
  • for loop

Pregunta 8

Pregunta
What will be the result of executing the following code?
Respuesta
  • The variable x will contain the values 0 through 5.
  • An array of 6 values, all initialized to 0 and referenced by the variable x, will be created.
  • A compiler error will occur.
  • An array of 6 values, ranging from 0 through 5 and referenced by the variable x, will be created.

Pregunta 9

Pregunta
What will be displayed when the following code is executed?
Respuesta
  • 45678.259
  • 45,678.26
  • 0,045,678.26
  • 45,678.3

Pregunta 10

Pregunta
What will be the value of bonus after the following code is executed?
Respuesta
  • 1000
  • 500
  • 1250
  • 750

Pregunta 11

Pregunta
In an if-else statement, if the boolean expression is false
Respuesta
  • no statements or blocks are executed.
  • the statement or block following the else is executed.
  • the first statement or block is executed.
  • all statements or blocks are executed.

Pregunta 12

Pregunta
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?
Respuesta
  • while (inputFile.hasNext())
  • while (!inputFile.EOF)
  • while (inputFile.nextLine == " ")
  • while (inputFile != null)

Pregunta 13

Pregunta
What would be the value of discountRate after the following statements are executed?
Respuesta
  • 0.04
  • 0.0
  • 0.03
  • 0.05

Pregunta 14

Pregunta
A ________ is a boolean variable that signals when some condition exists in the program.
Respuesta
  • flag
  • block
  • case
  • sentinel

Pregunta 15

Pregunta
You should not define a class field that is dependent upon the values of other class fields
Respuesta
  • in order to avoid having stale data.
  • because it should be defined in another class.
  • in order to keep it current.
  • because it is redundant.

Pregunta 16

Pregunta
Variables are classified according to their
Respuesta
  • values
  • data type
  • names
  • location in memory.

Pregunta 17

Pregunta
A class that is defined inside of another class is called a(n)
Respuesta
  • inner class
  • helper class
  • nested class
  • enumerated class

Pregunta 18

Pregunta
Because Java byte code is the same on all computers, compiled Java programs
Respuesta
  • must be re-compiled for each different machine it is run on.
  • cannot run on computers with different operating systems.
  • are highly portable.
  • are non-existent.

Pregunta 19

Pregunta
Java requires that the boolean expression being tested by an if statement be enclosed in
Respuesta
  • a set of double quotes.
  • a set of brackets.
  • a set of braces.
  • a set of parentheses.

Pregunta 20

Pregunta
The scope of a local variable is
Respuesta
  • the entire class.
  • inside the parentheses of a method header.
  • the method in which they are defined.
  • inside the class, but not inside any method.

Pregunta 21

Pregunta
What will be returned from the method, if the following is the method header?
Respuesta
  • the address of an object of the Rectangle class
  • the values stored in the data members of the Rectangle object
  • a null value
  • an object that is contained in the class Rectangle

Pregunta 22

Pregunta
How many bits are in a byte?
Respuesta
  • 4
  • 8
  • 16
  • 32

Pregunta 23

Pregunta
What will be the value of x after the following code is executed?
Respuesta
  • 110
  • 90
  • 10
  • 100

Pregunta 24

Pregunta
If you do not provide initialization values for a class's numeric fields, they will
Respuesta
  • cause a runtime error.
  • contain an unknown value.
  • cause a compiler error.
  • be automatically initialized with 0.

Pregunta 25

Pregunta
________ operators are used to determine whether a specific relationship exists between two values.
Respuesta
  • Relational
  • Arithmetic
  • Logical
  • Assignment

Pregunta 26

Pregunta
Using a counter-controlled while loop, write Java code to compute the sum of the integers from 1 to 100, inclusively, and output that result to the console. You will declare the integer variable num to count the number of executions (in the counter-controlled loop) and initialize it to 1. You will also declare the integer variable sum to store your computation result and initialize it to 0. Be sure to print your result to the console.
Respuesta
  • True
  • False

Pregunta 27

Pregunta
How many times will the following for loop be executed?
Respuesta
  • 11
  • 12
  • 10
  • 0

Pregunta 28

Pregunta
This type of loop will always be executed at least once.
Respuesta
  • pretest
  • posttest
  • infinite
  • conditional

Pregunta 29

Pregunta
Before entering a loop to compute a running total, the program should first
Respuesta
  • know exactly how many values there are to total.
  • set all variables to zero.
  • read all the values into main memory.
  • set the accumulator variable to an initial value, usually zero.

Pregunta 30

Pregunta
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
Respuesta
  • instances
  • relationships
  • methods
  • fields

Pregunta 31

Pregunta
After the header, the body of the method appears inside a set of
Respuesta
  • brackets, [].
  • braces, {}.
  • parentheses, ().
  • double quotes, "" .

Pregunta 32

Pregunta
A for loop normally performs which of these steps?
Respuesta
  • update the control variable during each iteration
  • test the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value
  • initialize a control variable to a starting value
  • All of these

Pregunta 33

Pregunta
In UML diagrams, what symbol indicates that a member is public?
Respuesta
  • *
  • +
  • #
  • -

Pregunta 34

Pregunta
How many times will the following do-while loop be executed?
Respuesta
  • 3
  • 5
  • 1
  • 4

Pregunta 35

Pregunta
What would be the value of discountRate after the following statements are executed?
Respuesta
  • 0.04
  • 0.0
  • 0.06
  • 0.08

Pregunta 36

Pregunta
A method (NEED TO FIND ANSWER)
Respuesta
  • must have at least two parameter variables. (NOT THIS ONE)
  • may have zero or more parameter variables.
  • may have only one parameter variables.
  • never has parameter variables.

Pregunta 37

Pregunta
What is the result of the following expression?
Respuesta
  • -50
  • 25
  • 5
  • -5

Pregunta 38

Pregunta
What will be the result of the following code?
Respuesta
  • The value variable will contain the lowest value in the numbers array.
  • The value variable will contain the average of all the values in the numbers array.
  • The value variable will contain the sum of all the values in the numbers array.
  • The value variable will contain the highest value in the numbers array.

Pregunta 39

Pregunta
A loop that executes as long as a particular condition exists is called a(n) ________ loop.
Respuesta
  • count-controlled
  • infinite
  • relational
  • conditional

Pregunta 40

Pregunta
UML diagrams do not contain
Respuesta
  • object names
  • class names
  • methods
  • fields

Pregunta 41

Pregunta
To print "Hello, world" on the monitor, use the following Java statement:
Respuesta
  • SystemOutPrintln('Hello, world');
  • system.out.println{Hello, world};
  • System.out.println("Hello, world");
  • System Print = "Hello, world";

Pregunta 42

Pregunta
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
Respuesta
  • str1 == str2
  • str1 + str2
  • str1 && str2
  • str1.equals(str2)

Pregunta 43

Pregunta
What will be displayed after the following code has been executed?
Respuesta
  • 10
  • 100
  • The code contains an error and will not compile.
  • 120

Pregunta 44

Pregunta
The key word new
Respuesta
  • creates a new class.
  • creates an object in memory.
  • creates a new Java byte code file.
  • creates a new variable in memory.

Pregunta 45

Pregunta
Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
Respuesta
  • str1 || str2
  • str1.equalsInsensitive(str2)
  • str1 != str2
  • str1.equalsIgnoreCase(str2)

Pregunta 46

Pregunta
How many times will the following do-while loop be executed?
Respuesta
  • 1
  • 4
  • 5
  • 0

Pregunta 47

Pregunta
What will be the value of x after the following code is executed?
Respuesta
  • 30
  • 40
  • 50
  • 25

Pregunta 48

Pregunta
A UML diagram uses the ________ symbol to indicate that a member is private.
Respuesta
  • -
  • #
  • +
  • *

Pregunta 49

Pregunta
What will be the value of x after the following code is executed?
Respuesta
  • 135
  • 60
  • 75
  • 15

Pregunta 50

Pregunta
Which of the following is not a rule that must be followed when naming identifiers?
Respuesta
  • Uppercase and lowercase characters are distinct.
  • The first character must be one of the letters a-z, A-Z, an underscore or a dollar sign.
  • After the first character, you may use the letters a-z, A-Z, an underscore, a dollar sign, or digits 0-9.
  • Identifiers can contain spaces.

Pregunta 51

Pregunta
A computer program is
Respuesta
  • a set of instructions that enable the computer to solve a problem or perform a task.
  • pseudocode.
  • a flow chart.
  • main memory

Pregunta 52

Pregunta
In all but rare cases, loops must contain within themselves
Respuesta
  • arithmetic operators.
  • if statements.
  • nested loops.
  • a way to terminate.

Pregunta 53

Pregunta
A method's signature consists of
Respuesta
  • the return type, the method name, and the parameter list.
  • the return type and the method name.
  • the method name and the parameter list.
  • the size of the method in memory.

Pregunta 54

Pregunta
What does the following UML diagram entry mean?
Respuesta
  • a private method with no parameters that returns a double data type
  • a public method with a parameter of data type double that does not return a value
  • a private field called Height that is a double data type
  • a public field called Height that is a double data type

Pregunta 55

Pregunta
Using a for loop, write Java code that prints out all multiples of 5 from 0 to 100, inclusively, to the console.
Respuesta
  • True
  • False

Pregunta 56

Pregunta
A loop that repeats a specific number of times is known as a(n) ________ loop.
Respuesta
  • pretest
  • count-controlled
  • infinite
  • conditional

Pregunta 57

Pregunta
What will be displayed when the following code is executed?
Respuesta
  • 45,678.3
  • 45,678.259
  • 45,678.26
  • 45678.259

Pregunta 58

Pregunta
What will be the values of ans, x, and y after the following statements are executed?
Respuesta
  • ans = 45, x = 50, y = 50
  • ans = 60, x = 0, y = 50
  • ans = 45, x = 50, y = 0
  • ans = 60, x = 50, y =100

Pregunta 59

Pregunta
What would be the value of x after the following statements were executed?
Respuesta
  • 5
  • 20
  • 30
  • 25

Pregunta 60

Pregunta
When working with the PrintWriter class, which of the following import statements should you have near the top of your program?
Respuesta
  • import javax.swing.*;
  • import java.file.*;
  • import javac.io.*;
  • import java.io.*;

Pregunta 61

Pregunta
The boolean expression in an if statement must evaluate to
Respuesta
  • positive or negative.
  • degrees or radians.
  • left or right.
  • true or false.

Pregunta 62

Pregunta
This is a named storage location in the computer's memory.
Respuesta
  • Constant
  • Variable
  • Literal
  • Operator

Pregunta 63

Pregunta
Methods that operate on an object's fields are called
Respuesta
  • instance methods
  • instance variables
  • private methods
  • public methods

Pregunta 64

Pregunta
The variable used to keep the running total is called a(n)
Respuesta
  • sentinel
  • summation
  • accumulator
  • integer

Pregunta 65

Pregunta
If object1 and object2 are objects of the same class, to make object2 a copy of object1
Respuesta
  • use an assignment statement to make object2 a copy of object1.
  • use the copy method that is a part of the Java API.
  • write a method for the class that will make a field by field copy of object1 data members into object2 data members.
  • use the default constructor to create object2 with object1 data members.

Pregunta 66

Pregunta
If you wish to use the System.out.printf method to print a string argument, use the ________ format specifier.
Respuesta
  • %f
  • %s
  • %d
  • %b

Pregunta 67

Pregunta
A static field is created by placing the key word static
Respuesta
  • in brackets, before the field's data type.
  • after the field name.
  • after the access specifier and field's data type.
  • after the access specifier and before the field's data type.

Pregunta 68

Pregunta
Character literals are enclosed in ________, and string literals are enclosed in ________.
Respuesta
  • single quotes, double quotes
  • double quotes, double quotes
  • single quotes, single quotes
  • double quotes, single quotes

Pregunta 69

Pregunta
What will be the value of x after the following code is executed?
Respuesta
  • 14
  • 16
  • 15
  • 0

Pregunta 70

Pregunta
Which of the following expressions determines whether the char variable chrA is not equal to the letter 'A'?
Respuesta
  • chrA || 'A'
  • chrA == 'A'
  • chrA.notEquals('A')
  • chrA != 'A'

Pregunta 71

Pregunta
A block of code is enclosed in a set of
Respuesta
  • brackets
  • braces
  • double quotes
  • parentheses

Pregunta 72

Pregunta
A class's responsibilities include
Respuesta
  • both the things a class is responsible for knowing and the things a class is responsible for doing
  • neither the things a class is responsible for knowing nor the things a class is responsible for doing
  • the things a class is responsible for knowing.
  • the things a class is responsible for doing.

Pregunta 73

Pregunta
What is syntax? (NEED RIGHT ANSWER)
Respuesta
  • Words that have a special meaning in the programming language.
  • Words or names defined by the programmer. (NOT ANSWER)
  • Rules that must be followed when writing a program.
  • Symbols or words that perform operations.

Pregunta 74

Pregunta
Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
Respuesta
  • File file = new File("MyFile.txt");
  • File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
  • Scanner inputFile = new Scanner("MyFile.txt");
  • PrintWriter inputFile = new PrintWriter("MyFile.txt");

Pregunta 75

Pregunta
What is the value of ans after the following code has been executed?
Respuesta
  • 30
  • 50
  • 80
  • The code contains an error and will not compile.

Pregunta 76

Pregunta
The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.
Respuesta
  • null
  • block
  • flag
  • if

Pregunta 77

Pregunta
Rewrite the following if-else if statement as a switch statement:
Respuesta
  • True
  • False

Pregunta 78

Pregunta
What will be displayed when the following code is executed? (NEED RIGHT ANSWER)
Respuesta
  • 30
  • The code contains an error and will not compile. (NOT ANSWER)
  • 20
  • 40

Pregunta 79

Pregunta
What is the result of the following expression?
Respuesta
  • 105
  • 8
  • 12
  • 7

Pregunta 80

Pregunta
A search algorithm
Respuesta
  • arranges elements in ascending order.
  • is rarely used with arrays.
  • arranges elements in descending order.
  • is used to locate a specific item in a larger collection of data.

Pregunta 81

Pregunta
Overloading is
Respuesta
  • having two or more methods with the same name, but different signatures.
  • having two or more methods with the same signature.
  • writing a method that does too much processing.
  • writing a program that is too large to fit in memory. (NOT RIGHT)

Pregunta 82

Pregunta
A constructor
Respuesta
  • always has an access specifier of private.
  • always accepts two arguments.
  • has return type of void.
  • has the same name as the class.

Pregunta 83

Pregunta
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by
Respuesta
  • using the public access specifier on the class methods.
  • using the private access specifier on the class methods.
  • using the private access specifier on the class fields.
  • using the private access specifier on the class definition.

Pregunta 84

Pregunta
Which of the following expressions will determine whether x is less than or equal to y?
Respuesta
  • x =< y
  • x <= y
  • x >= y
  • x => y

Pregunta 85

Pregunta
When saving a Java source file, save it with an extension of
Respuesta
  • .class.
  • .java.
  • .javac.
  • .src.

Pregunta 86

Pregunta
Another term for an object of a class is a(n)
Respuesta
  • instance
  • method
  • member
  • access specifier

Pregunta 87

Pregunta
Which of the following statements determines whether temp is within the range of 0 through 100?
Respuesta
  • if (temp >= 0 && temp <= 100)
  • if (temp > 0 || temp < 100)
  • if (temp >= 0 || temp <= 100)
  • if (temp > 0 && temp < 100)

Pregunta 88

Pregunta
Using a switch statement, write Java code to output the season of the year to the console based on the value of an integer variable called month according to the following:
Respuesta
  • True
  • False

Pregunta 89

Pregunta
What will be the result of the following code? (NEED ANSWER)
Respuesta
  • All the values in the array will be initialized to 10.0.
  • A runtime error will occur. (NOT RIGHT)
  • All the values in the array, except the first, will be set to 10.0.
  • The code contains a syntax error and will not compile.

Pregunta 90

Pregunta
A constructor is a method that
Respuesta
  • removes the object from memory.
  • performs initialization or setup operations.
  • never receives any arguments.
  • returns an object of the class.

Pregunta 91

Pregunta
A group of related classes is called a(n)
Respuesta
  • archive
  • package
  • collection
  • attachment

Pregunta 92

Pregunta
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
Respuesta
  • int number = inputFile.next();
  • int number = inputFile.integer();
  • int number = inputFile.readInt();
  • int number = inputFile.nextInt();

Pregunta 93

Pregunta
What does the following code do?
Respuesta
  • It establishes a connection with a file named filename.
  • It allows the user to enter the name of the file that data will to be written to.
  • Nothing. The code contains a syntax error.
  • It writes to a file named filename.

Pregunta 94

Pregunta
The ________ loop is ideal in situations where you always want the loop to iterate at least once.
Respuesta
  • for
  • do-while
  • pretest
  • while

Pregunta 95

Pregunta
A ________ is a value that signals when the end of a list of values has been reached.
Respuesta
  • sentinel
  • token
  • delimiter
  • terminal

Pregunta 96

Pregunta
________ is the term for the relationship created by object aggregation.
Respuesta
  • Inner Class
  • One-to-many
  • "Is a"
  • "Has a"

Pregunta 97

Pregunta
Which Scanner class method reads a String?
Respuesta
  • nextLine
  • charAt
  • nextString
  • getLine

Pregunta 98

Pregunta
Enclosing a group of statements inside a set of braces creates
Respuesta
  • a block of statements.
  • a relational operator.
  • an if-else statement.
  • an expression.

Pregunta 99

Pregunta
This statement tells the compiler where to find the JOptionPane class and makes it available to your program.
Respuesta
  • import javax.JOptionPane;
  • import javax.swing.JOptionPane;
  • import Java.Swing.JOptionPane;
  • import JOptionPane;

Pregunta 100

Pregunta
Which of the following is not a valid Java comment?
Respuesta
  • /** Comment 1 */
  • // Comment 3
  • */ Comment 2 /*
  • /* Comment 4 */
Mostrar resumen completo Ocultar resumen completo

Similar

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Data Analytics
anelvr