Java (Ch 1 - Ch 7)

Beschreibung

Computer Science Quiz am Java (Ch 1 - Ch 7), erstellt von Heather Williams am 23/06/2018.
Heather Williams
Quiz von Heather Williams, aktualisiert more than 1 year ago
Heather Williams
Erstellt von Heather Williams vor mehr als 6 Jahre
226
0

Zusammenfassung der Ressource

Frage 1

Frage
Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
Antworten
  • 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);

Frage 2

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

Frage 3

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

Frage 4

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

Frage 5

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

Frage 6

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

Frage 7

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

Frage 8

Frage
What will be the result of executing the following code?
Antworten
  • 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.

Frage 9

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

Frage 10

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

Frage 11

Frage
In an if-else statement, if the boolean expression is false
Antworten
  • 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.

Frage 12

Frage
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?
Antworten
  • while (inputFile.hasNext())
  • while (!inputFile.EOF)
  • while (inputFile.nextLine == " ")
  • while (inputFile != null)

Frage 13

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

Frage 14

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

Frage 15

Frage
You should not define a class field that is dependent upon the values of other class fields
Antworten
  • 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.

Frage 16

Frage
Variables are classified according to their
Antworten
  • values
  • data type
  • names
  • location in memory.

Frage 17

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

Frage 18

Frage
Because Java byte code is the same on all computers, compiled Java programs
Antworten
  • 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.

Frage 19

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

Frage 20

Frage
The scope of a local variable is
Antworten
  • 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.

Frage 21

Frage
What will be returned from the method, if the following is the method header?
Antworten
  • 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

Frage 22

Frage
How many bits are in a byte?
Antworten
  • 4
  • 8
  • 16
  • 32

Frage 23

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

Frage 24

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

Frage 25

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

Frage 26

Frage
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.
Antworten
  • True
  • False

Frage 27

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

Frage 28

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

Frage 29

Frage
Before entering a loop to compute a running total, the program should first
Antworten
  • 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.

Frage 30

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

Frage 31

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

Frage 32

Frage
A for loop normally performs which of these steps?
Antworten
  • 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

Frage 33

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

Frage 34

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

Frage 35

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

Frage 36

Frage
A method (NEED TO FIND ANSWER)
Antworten
  • 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.

Frage 37

Frage
What is the result of the following expression?
Antworten
  • -50
  • 25
  • 5
  • -5

Frage 38

Frage
What will be the result of the following code?
Antworten
  • 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.

Frage 39

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

Frage 40

Frage
UML diagrams do not contain
Antworten
  • object names
  • class names
  • methods
  • fields

Frage 41

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

Frage 42

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

Frage 43

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

Frage 44

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

Frage 45

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

Frage 46

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

Frage 47

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

Frage 48

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

Frage 49

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

Frage 50

Frage
Which of the following is not a rule that must be followed when naming identifiers?
Antworten
  • 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.

Frage 51

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

Frage 52

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

Frage 53

Frage
A method's signature consists of
Antworten
  • 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.

Frage 54

Frage
What does the following UML diagram entry mean?
Antworten
  • 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

Frage 55

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

Frage 56

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

Frage 57

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

Frage 58

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

Frage 59

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

Frage 60

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

Frage 61

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

Frage 62

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

Frage 63

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

Frage 64

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

Frage 65

Frage
If object1 and object2 are objects of the same class, to make object2 a copy of object1
Antworten
  • 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.

Frage 66

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

Frage 67

Frage
A static field is created by placing the key word static
Antworten
  • 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.

Frage 68

Frage
Character literals are enclosed in ________, and string literals are enclosed in ________.
Antworten
  • single quotes, double quotes
  • double quotes, double quotes
  • single quotes, single quotes
  • double quotes, single quotes

Frage 69

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

Frage 70

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

Frage 71

Frage
A block of code is enclosed in a set of
Antworten
  • brackets
  • braces
  • double quotes
  • parentheses

Frage 72

Frage
A class's responsibilities include
Antworten
  • 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.

Frage 73

Frage
What is syntax? (NEED RIGHT ANSWER)
Antworten
  • 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.

Frage 74

Frage
Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
Antworten
  • 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");

Frage 75

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

Frage 76

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

Frage 77

Frage
Rewrite the following if-else if statement as a switch statement:
Antworten
  • True
  • False

Frage 78

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

Frage 79

Frage
What is the result of the following expression?
Antworten
  • 105
  • 8
  • 12
  • 7

Frage 80

Frage
A search algorithm
Antworten
  • 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.

Frage 81

Frage
Overloading is
Antworten
  • 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)

Frage 82

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

Frage 83

Frage
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by
Antworten
  • 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.

Frage 84

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

Frage 85

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

Frage 86

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

Frage 87

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

Frage 88

Frage
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:
Antworten
  • True
  • False

Frage 89

Frage
What will be the result of the following code? (NEED ANSWER)
Antworten
  • 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.

Frage 90

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

Frage 91

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

Frage 92

Frage
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?
Antworten
  • int number = inputFile.next();
  • int number = inputFile.integer();
  • int number = inputFile.readInt();
  • int number = inputFile.nextInt();

Frage 93

Frage
What does the following code do?
Antworten
  • 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.

Frage 94

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

Frage 95

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

Frage 96

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

Frage 97

Frage
Which Scanner class method reads a String?
Antworten
  • nextLine
  • charAt
  • nextString
  • getLine

Frage 98

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

Frage 99

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

Frage 100

Frage
Which of the following is not a valid Java comment?
Antworten
  • /** Comment 1 */
  • // Comment 3
  • */ Comment 2 /*
  • /* Comment 4 */
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

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