1/53
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is output with the statement System.out.println(““+x+y); if x and y are int values where x=10 and y=5?
105
Use the following class definition to answer the following question.
public class Questions1_4 {
public static void main(String[] args) {
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
// a program that demonstrates the differences between print, println, and how + works
An error in a program that results in the program outputting $100 instead of the correct answer, $250 is
a logical error
Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following?
if (count != 0 && total / count > max) max = total / count;
The condition short circuits and the assignment statement is not executed
In order to determine the type that a polymorphic variable refers to, the decision is made
by the Java run-time environment at run time
Which of the following lists of instance data are accessible in A3?
x, z, a, q
Which of the following is true regarding the use of instance variable y of class A1?
it is accessible only in A1
If a method does not have a return statement, then
it must be a void method
In order to preserve encapsulation of an object, we would do all of the following except for which one?
Make the class final
A variable whose scope is restricted to the method where it was declared is known as a(n)
local variable
Assume values is an int array that is currently filled to capacity, with the values:
The statement System.out.pringln(values[7]); will
cause an ArrayOutOfBoundsException to be thrown
What is a mutator method?
A method that modifies a value
Consider the following class definition:
If q1 and q2 are objects of Q, then q1.equals(q2)
is true if q1 and q2 reference the same Q object
What will be the result of the following assignment statement? Assume b = 5 and c = 10.
int a = b * (-c + 2)/2;
-20
Assume values is an int array that is currently filled to capacity, with the following values:
What is returned by values[3]?
2
A class’ constructor usually defines
how an object is initialized
Assume that x,y, and z are all ints equal to 50, 20, and 6 respectively. What is the result of x/y/z?
0
For this question, refer to the class defined below:
import java.util.Scanner;
public class Questions {
public static void main(String[] args) {
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x.scan.nextInt();
System.out.println("Enter another integer value");
y.scan.nextInt();
System.out.println("Enter a third integer value");
z.scan.nextInt();
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
What is the output if x = 0, y = 1, and z = 1?
0.0
All classes in Java are directly or indirectly subclasses of the ______ class
Reference
Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending on a student's test score.
if(score >= 90) grade = 'A';
if(score >= 80) grade = 'B';
if(score >= 70) grade = 'C';
if(score >= 60) grade = 'D';
else grade = 'F';
This code will work correctly only if score < 70
Forgetting a semicolon will cause
a syntax error
Of the following if statements, which one correctly executes three instructions if the condition is true?
if (x < 0)
{
a = b * 2;
y = x;
z = a - y;
}
Which of the following would be a legal Java identifier?
i
Assume values is an int array that is currently filled to capacity, with the following values:
Which of the following loops would adequately add 1 to each element stored in values?
for(j=0;j<=values.length;j++) values[j]++;
If you want to output the text “hi there,” including quote marks, which of the following could do that?
System.out.println("\"hi there\"");
Which of the following reserved words in Java is used to create an instance of a class?
new
For the following question, refer to the class below:
import java.util.Scanner;
public class Questions {
public static void main(String[] args) {
int x, y, z;
double average;
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer value");
x.scan.nextInt();
System.out.println("Enter another integer value");
y.scan.nextInt();
System.out.println("Enter a third integer value");
z.scan.nextInt();
average = (x + y + z) / 3;
System.out.println("The result of my calculation is " + average);
}
}
Questions computes
The average of x, y, and z as a double, but the result may not be accurate
Assume values is an int array that is currently filled to capacity, with the following values:
What is the value of values.length?
7
Consider the following class definition:
Which of the following is true about the class Q?
it’s parent class is Object
Having multiple class methods of the same name where each method has a different number of or type of parameters is known as
method overloading
Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?
for(int i=0;i<5;i++)
x += i;
10
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
if (x > 0) x++;
else if (x < 0) x--;
The instruction super(); does which of the following?
calls the constructor as defined in the current class' parent class
The behavior of an object is defined by the object's
methods
What value will z have if we execute the following assignment statement?
double z = 5 / 10;
z will equal 0.0
Use the following class definition to answer the following question.
public class Questions1_4 {
public static void main(String[] args) {
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
How many lines of output are provided by this program?
2
A case is required in which of the following situations?
storing a double in an int
Which character below is not allowed in an identifier?
^
The relationship between a class and an object is best described as
objects are instances of classes
Consider the following statement:
System.out.println(“1 big bad wold\t8 the 3 little pigs\n4dinner\r2night”)';
The statement will output__ lines of text.
2
Which of the following lists of instance data are accessible in class A2?
x, z, a, b
To define a class that will represent a car, which of the following definitions is most appropriate?
public class Car
Which of the following would be a good variable name for the current value of a stock?
currentStockVal
If you want to store into the String name the value “George Bush” you would use which statement?
Any of the above would work
Comments should
be insightful and explain what the instruction’s intent is
Use the following class definition to answer the following definition.
public class Questions1_4 {
public static void main(String[] args) {
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The final println command will output
“But notin Texas”
Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?
foo(0 / 1.2 * 3);
Use the following class definition to answer the following question.
public class Questions1_4 {
public static void main(String[] args) {
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
The program will print the word "Here" and then print
“There Everywhere” on the same line as “Here”
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?
Math.sqrt(Math.abs(x));
Following Java naming convention, which of the following would be the best name for a class about store customers?
StoreCustomer
Which of the following is a legal Java identifier?
oneForAll
The “off-by-one” error associated with arrays arises because
the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far
Given the following assignment statement, which of the following answers is true regarding the order that the operators will be applied based on operator precedence?
a = (b + c) * d / e - f;
+,*,/,-
Which of the following is true with respect to A1, A2 and A3?
A3 is a subclass of A2 and A2 is a subclass of A1