Java (Ch 1 - Ch 7)

Descrição

Computer Science Quiz sobre Java (Ch 1 - Ch 7), criado por Heather Williams em 23-06-2018.
Heather Williams
Quiz por Heather Williams, atualizado more than 1 year ago
Heather Williams
Criado por Heather Williams quase 6 anos atrás
209
0

Resumo de Recurso

Questão 1

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

Questão 2

Questão
When an object is created, the attributes associated with the object are called
Responda
  • instance fields
  • fixed attributes
  • instance methods
  • class instances

Questão 3

Questão
What will be the value of x after the following code is executed?
Responda
  • 110
  • 90
  • 130
  • 210

Questão 4

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

Questão 5

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

Questão 6

Questão
What would be the value of discountRate after the following statements are executed?
Responda
  • 0.03
  • 0.0
  • 0.01
  • 0.05

Questão 7

Questão
The ________ is ideal in situations where the exact number of iterations is known.
Responda
  • posttest loop
  • while loop
  • do-while loop
  • for loop

Questão 8

Questão
What will be the result of executing the following code?
Responda
  • 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.

Questão 9

Questão
What will be displayed when the following code is executed?
Responda
  • 45678.259
  • 45,678.26
  • 0,045,678.26
  • 45,678.3

Questão 10

Questão
What will be the value of bonus after the following code is executed?
Responda
  • 1000
  • 500
  • 1250
  • 750

Questão 11

Questão
In an if-else statement, if the boolean expression is false
Responda
  • 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.

Questão 12

Questão
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?
Responda
  • while (inputFile.hasNext())
  • while (!inputFile.EOF)
  • while (inputFile.nextLine == " ")
  • while (inputFile != null)

Questão 13

Questão
What would be the value of discountRate after the following statements are executed?
Responda
  • 0.04
  • 0.0
  • 0.03
  • 0.05

Questão 14

Questão
A ________ is a boolean variable that signals when some condition exists in the program.
Responda
  • flag
  • block
  • case
  • sentinel

Questão 15

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

Questão 16

Questão
Variables are classified according to their
Responda
  • values
  • data type
  • names
  • location in memory.

Questão 17

Questão
A class that is defined inside of another class is called a(n)
Responda
  • inner class
  • helper class
  • nested class
  • enumerated class

Questão 18

Questão
Because Java byte code is the same on all computers, compiled Java programs
Responda
  • 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.

Questão 19

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

Questão 20

Questão
The scope of a local variable is
Responda
  • 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.

Questão 21

Questão
What will be returned from the method, if the following is the method header?
Responda
  • 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

Questão 22

Questão
How many bits are in a byte?
Responda
  • 4
  • 8
  • 16
  • 32

Questão 23

Questão
What will be the value of x after the following code is executed?
Responda
  • 110
  • 90
  • 10
  • 100

Questão 24

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

Questão 25

Questão
________ operators are used to determine whether a specific relationship exists between two values.
Responda
  • Relational
  • Arithmetic
  • Logical
  • Assignment

Questão 26

Questão
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.
Responda
  • True
  • False

Questão 27

Questão
How many times will the following for loop be executed?
Responda
  • 11
  • 12
  • 10
  • 0

Questão 28

Questão
This type of loop will always be executed at least once.
Responda
  • pretest
  • posttest
  • infinite
  • conditional

Questão 29

Questão
Before entering a loop to compute a running total, the program should first
Responda
  • 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.

Questão 30

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

Questão 31

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

Questão 32

Questão
A for loop normally performs which of these steps?
Responda
  • 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

Questão 33

Questão
In UML diagrams, what symbol indicates that a member is public?
Responda
  • *
  • +
  • #
  • -

Questão 34

Questão
How many times will the following do-while loop be executed?
Responda
  • 3
  • 5
  • 1
  • 4

Questão 35

Questão
What would be the value of discountRate after the following statements are executed?
Responda
  • 0.04
  • 0.0
  • 0.06
  • 0.08

Questão 36

Questão
A method (NEED TO FIND ANSWER)
Responda
  • 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.

Questão 37

Questão
What is the result of the following expression?
Responda
  • -50
  • 25
  • 5
  • -5

Questão 38

Questão
What will be the result of the following code?
Responda
  • 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.

Questão 39

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

Questão 40

Questão
UML diagrams do not contain
Responda
  • object names
  • class names
  • methods
  • fields

Questão 41

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

Questão 42

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

Questão 43

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

Questão 44

Questão
The key word new
Responda
  • creates a new class.
  • creates an object in memory.
  • creates a new Java byte code file.
  • creates a new variable in memory.

Questão 45

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

Questão 46

Questão
How many times will the following do-while loop be executed?
Responda
  • 1
  • 4
  • 5
  • 0

Questão 47

Questão
What will be the value of x after the following code is executed?
Responda
  • 30
  • 40
  • 50
  • 25

Questão 48

Questão
A UML diagram uses the ________ symbol to indicate that a member is private.
Responda
  • -
  • #
  • +
  • *

Questão 49

Questão
What will be the value of x after the following code is executed?
Responda
  • 135
  • 60
  • 75
  • 15

Questão 50

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

Questão 51

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

Questão 52

Questão
In all but rare cases, loops must contain within themselves
Responda
  • arithmetic operators.
  • if statements.
  • nested loops.
  • a way to terminate.

Questão 53

Questão
A method's signature consists of
Responda
  • 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.

Questão 54

Questão
What does the following UML diagram entry mean?
Responda
  • 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

Questão 55

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

Questão 56

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

Questão 57

Questão
What will be displayed when the following code is executed?
Responda
  • 45,678.3
  • 45,678.259
  • 45,678.26
  • 45678.259

Questão 58

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

Questão 59

Questão
What would be the value of x after the following statements were executed?
Responda
  • 5
  • 20
  • 30
  • 25

Questão 60

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

Questão 61

Questão
The boolean expression in an if statement must evaluate to
Responda
  • positive or negative.
  • degrees or radians.
  • left or right.
  • true or false.

Questão 62

Questão
This is a named storage location in the computer's memory.
Responda
  • Constant
  • Variable
  • Literal
  • Operator

Questão 63

Questão
Methods that operate on an object's fields are called
Responda
  • instance methods
  • instance variables
  • private methods
  • public methods

Questão 64

Questão
The variable used to keep the running total is called a(n)
Responda
  • sentinel
  • summation
  • accumulator
  • integer

Questão 65

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

Questão 66

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

Questão 67

Questão
A static field is created by placing the key word static
Responda
  • 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.

Questão 68

Questão
Character literals are enclosed in ________, and string literals are enclosed in ________.
Responda
  • single quotes, double quotes
  • double quotes, double quotes
  • single quotes, single quotes
  • double quotes, single quotes

Questão 69

Questão
What will be the value of x after the following code is executed?
Responda
  • 14
  • 16
  • 15
  • 0

Questão 70

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

Questão 71

Questão
A block of code is enclosed in a set of
Responda
  • brackets
  • braces
  • double quotes
  • parentheses

Questão 72

Questão
A class's responsibilities include
Responda
  • 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.

Questão 73

Questão
What is syntax? (NEED RIGHT ANSWER)
Responda
  • 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.

Questão 74

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

Questão 75

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

Questão 76

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

Questão 77

Questão
Rewrite the following if-else if statement as a switch statement:
Responda
  • True
  • False

Questão 78

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

Questão 79

Questão
What is the result of the following expression?
Responda
  • 105
  • 8
  • 12
  • 7

Questão 80

Questão
A search algorithm
Responda
  • 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.

Questão 81

Questão
Overloading is
Responda
  • 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)

Questão 82

Questão
A constructor
Responda
  • always has an access specifier of private.
  • always accepts two arguments.
  • has return type of void.
  • has the same name as the class.

Questão 83

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

Questão 84

Questão
Which of the following expressions will determine whether x is less than or equal to y?
Responda
  • x =< y
  • x <= y
  • x >= y
  • x => y

Questão 85

Questão
When saving a Java source file, save it with an extension of
Responda
  • .class.
  • .java.
  • .javac.
  • .src.

Questão 86

Questão
Another term for an object of a class is a(n)
Responda
  • instance
  • method
  • member
  • access specifier

Questão 87

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

Questão 88

Questão
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:
Responda
  • True
  • False

Questão 89

Questão
What will be the result of the following code? (NEED ANSWER)
Responda
  • 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.

Questão 90

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

Questão 91

Questão
A group of related classes is called a(n)
Responda
  • archive
  • package
  • collection
  • attachment

Questão 92

Questão
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?
Responda
  • int number = inputFile.next();
  • int number = inputFile.integer();
  • int number = inputFile.readInt();
  • int number = inputFile.nextInt();

Questão 93

Questão
What does the following code do?
Responda
  • 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.

Questão 94

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

Questão 95

Questão
A ________ is a value that signals when the end of a list of values has been reached.
Responda
  • sentinel
  • token
  • delimiter
  • terminal

Questão 96

Questão
________ is the term for the relationship created by object aggregation.
Responda
  • Inner Class
  • One-to-many
  • "Is a"
  • "Has a"

Questão 97

Questão
Which Scanner class method reads a String?
Responda
  • nextLine
  • charAt
  • nextString
  • getLine

Questão 98

Questão
Enclosing a group of statements inside a set of braces creates
Responda
  • a block of statements.
  • a relational operator.
  • an if-else statement.
  • an expression.

Questão 99

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

Questão 100

Questão
Which of the following is not a valid Java comment?
Responda
  • /** Comment 1 */
  • // Comment 3
  • */ Comment 2 /*
  • /* Comment 4 */

Semelhante

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