ITP120 Chater 1 - 5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

One or more objects may be created from a(n) field. method. class. instance.

class.

The data contained in an object is known as the fields. the methods. the attributes. the classes.

the attributes.

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

"000.0"

Which symbol indicates that a member is private a UML diagram? - + # *

-

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x); 5.60 5.0 3.0 5.6

5.0

What is the result of the following expression? 17 % 3 * 2 - 12 + 15 105 7 8 12

7

Which of the following is not part of the programming process? defining and modeling the problem testing and debugging entering code and compiling it All of these are parts of the programming process.

All of these are parts of the programming process.

________ refers to the physical components that a computer is made of. Input Control unit Main memory Hardware

Hardware

Which of the following is not a rule that must be followed when naming identifiers? Identifiers can contain spaces. 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 the digits 0-9. Uppercase and lowercase characters are distinct.

Identifiers can contain spaces.

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y) x = 22, y = 4 x = 22, y = 88 x = 22, y = 26 Nothing. There is an error in the code.

Nothing. There is an error in the code.

Which of the following statements will create an object from the Random class? Random myNumber = new Random(); myNumber = new Random(); Random = new randomNumbers(); randomNumbers() = new Random();

Random myNumber = new Random();

Which of the following statements correctly creates a Scanner object for keyboard input? Scanner keyboard(System.in); Keyboard scanner = new Keyboard(System.in); Scanner kbd = new Scanner(System.keyboard); Scanner keyboard = new Scanner(System.in);

Scanner keyboard = new Scanner(System.in);

To print "Hello, world" on the monitor, which of the following Java statements should be used? SystemOutPrintln('Hello, world'); system.out.println(Hello, world); System Print = "Hello, world"; System.out.println("Hello, world");

System.out.println("Hello, world");

For the following code, which statement is not true? The radius field is not available to code written outside the Sphere class. The x field is available to code that is written outside the Sphere class. The z field is available to code written outside the Sphere class. The radius, x, y, and z fields are members of the Sphere class.

The z field is available to code written outside the Sphere class.

When a character is stored in memory, it is actually the ________ that is stored. floating-point value letter, symbol, or number Unicode number ASCII code

Unicode number

A Java program must have at least one of the following: a System.out.println(); statement a variable declaration a comment a class definition

a class definition

Which of the following is a value that is written into the code of a program? an assignment statement a variable a literal an operator

a literal

A runtime error is usually the result of a syntax error. a logical error. a compiler error. bad data.

a logical error.

What does the following UML diagram entry mean? + setHeight(h : double) : void a private method with no parameters that returns a double data type a public field called Height that is a double data type a public method with a parameter of data type double that does not return a value a private field called setHeight that is a double data type

a public method with a parameter of data type double that does not return a value

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

a set of parentheses.

RAM is usually a static type of memory, used for permanent storage. a volatile type of memory, used for temporary storage. an input/output device. secondary storage.

a volatile type of memory, used for temporary storage.

What is the following statement an example of? import java.util.Scanner; a wildcard import statement a conditional import statement an explicit import statement an unconditional import statement

an explicit import statement

A class's responsibilities include the things a class is responsible for doing. the things a class is responsible for knowing. both of these. neither of these.

both of these.

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

braces, { }

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

chrA != 'A'

A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data. component reusability classes data hiding procedures

data hiding

Variables of the boolean data type are useful for working with small integers. evaluating scientific notation. working with very large integers. evaluating conditions that are either true or false.

evaluating conditions that are either true or false.

It is common practice in object-oriented programming to make all of a class's methods private. fields public. fields and methods public. fields private.

fields private.

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

flag

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

if (temp >= 0 && temp <= 100)

Which is the key word used to import a class? use assume link import

import

Which statement tells the compiler where to find the JOptionPane class and makes it available to your program? import Java.Swing.JOptionPane; import JOptionPane; import javax.swing.JOptionPane; import javax.JOptionPane;

import javax.swing.JOptionPane;

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

in order to avoid having stale data.

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

instance fields.

Assume you are at the operating system command line and want to use the following command to compile a program: javac MyClass.java Before entering the command you must save the program with the .comp extension. close all open windows on your computer system. execute the java.sun.com program. make sure you are in the same directory or folder where the MyClass.java file is located.

make sure you are in the same directory or folder where the MyClass.java file is located.

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

methods

Which of the following expressions will generate a random number in the range of 1 through 10? myNumber = randomNumbers.nextInt(10) + 1; myNumber = randomNumbers.nextInt(11) - 1; myNumber = randomNumbers.nextInt(1) + 10; myNumber = randomNumbers.nextInt(10);

myNumber = randomNumbers.nextInt(10) + 1;

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

nextLine

UML diagrams do not contain class names. fields. methods. object names.

object names.

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

performs initialization or setup operations.

The two primary methods of programming in use today are hardware and software. desktop and mobile. practical and theoretical. procedural and object-oriented.

procedural and object-oriented.

Computers can do many different jobs because they are programmable. electronic. reliable. automated.

programmable.

A(n) ________ is used to write computer programs. operating system pseudocode document application programming language

programming language

The ________ method is used to display a message dialog. showDialog showMessageDialog messageDialogShow messageDialog

showMessageDialog

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

single quotes, double quotes

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

str1.equals(str2)

Variables are reserved words. symbolic names made up by the programmer and once created, their values cannot be changed. symbolic names made up by the programmer that represent memory locations. operators that perform operations on one or more operands.

symbolic names made up by the programmer that represent memory locations.

What is syntax? the words that have a special meaning in the programming language the rules that must be followed when writing a program the symbols or words that perform operations in a program the words or characters that are defined by the programmer

the rules that must be followed when writing a program

To indicate the data type of a variable in a UML diagram you specify the variable name followed by the data type. the variable name followed by a colon and the data type. the class name followed by the variable name followed by the data type. the data type followed by the variable name.

the variable name followed by a colon and the data type.

A flag may have the values of any Unicode character. of any range of integers. defined or undefined. true or false.

true or false.

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

true or false.

The simplest way to use the System.out.printf method is with a format string and one format specifier. with a format string and one or more format specifiers. with only one format specifier and no format string. with only a format string and no additional arguments.

with only a format string and no additional arguments.

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

x <= y

Which of the following statements will correctly convert the data type, if x is a float and y is a double? x = float y; x = (float)y; x = y;

x = (float)y;

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y); x = 37, y = 5 x = 9, y = 52 x = 160, y = 80 x = 32, y = 4

x = 37, y = 5


Ensembles d'études connexes

Central America, Colombia, and Venezuela

View Set

"Si" clauses : présent, futur simple, imparfait, plus que parfait, conditionnel présent ou conditionnel passé? Conjuguez le verbe en parenthèses selon besoin.

View Set

Assault, battery, False imprisonment. (Professional nursing & ethics)

View Set

Fundamentals of Netoworking FINAL v.7

View Set

Combo with "Western Civilization ch1,2,3 - EXAM 1"

View Set

AFI 36-2903 - Ornamentation and Accessories Standards (Male & Female)

View Set