1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the value of valOne after these lines are executed?
a) 0.5
b) 0
c) 0.0
d) none of the above
c) 0.0
What is the value of valTwo after these lines are executed?
a) 0.5
b) 0
c) 0.0
d) none of the above
d) none of the above
Returns an error
What is displayed after the main method is executed?
a) Student Age is 24
b) Student Age is 231
c) Student Age is userAge + 1
b) Student Age is 231
Choose from the following the best choice for a Java variable name that will refer to the average test score.
a) avg_test_score
b) avgTestScore
c) Test_score
d) ScOreS
b) avgTestScore
What are the values assigned to each variable after the following code is executed?
a = 4
b = 2.5
c = 15
d = 5.5
What is the value of the following boolean expression if a = true and b = false?
a) true
b) false
a) true
What is y after executing the statements?
a) 12
b) 10
c) 8
d) 6
b) 10
What will be the value of x after executing the following code?
a) 6
b) 5
c) 8
d) 7
c) 8
What is the output of the following code snippet?
a) 7.5
b) 5
c) 7
d) Compilation Error
c) 7
height h (area is one-half base time height. Which of these expressions fails to compute that?
a) (b*h) / 2.0
b) (1/2) * b * h
c) 0.5 * b * h
d) (1.0/2.0) * b * h
b) (1/2) * b * h
In Java, when you perform integer division, any fractional part is truncated, meaning the result will be an integer, and any remainder is discarded. So 1/2 is 0 and NOT 0.5
Which XXX completes the code to check for and read in doubles from the file, "myScores.txt"?
a) scnr.hasNext()
b) scnr.hasNextDouble()
c) hasNextDouble()
d) hasNextLine()
b) scnr.hasNextDouble()
What is the value of y that will be printed?
a) 5
b) 3
c) 0
d) 6
c) 0
½ gets 0.5, but its integer division so its 0
What is the value of the variable ‘result’?
a) 3
b) 2.25
c) 2
d) Error: The operands are different types and cannot be divided
b) 2.25
The variables y and z are both integers, and result is declared as a double. The expression y / (z + 1.0) involves both integer and floating-point arithmetic.
Let's break down the expression:
(z + 1.0) performs addition where 1.0 is a floating-point number. This forces the expression to be evaluated in floating-point arithmetic because there is at least one floating-point operand.
y / (z + 1.0) performs division. Here, y is an integer and (z + 1.0) is a double. When an integer is divided by a double, the result is automatically promoted to a double. This is due to the widening primitive conversion in Java.
So, result will store the result of the division operation, which is a double.
In JAVA, which keyword is used to implement a decision-making statement?
a) if
b) decide
c) case
d) select
a) if
In Java, which of the following is NOT a valid variable name?
a) $variableName
b) 1stVariable
c) variableName
b) 1stVariable
Given char variable x and char variable z, which assigns x with the character value held in z?
a) x=”z”;
b) x = z;
c) x = 'z';
d) 'x' = 'z';
b) x = z;
Suppose you are designing a class called Circle. Which of the following is the best way to define its members?
Suppose you are designing a class called Circle. Which access modifiers should be used for its members?
What will happen when we create an instance using this constructor?
a) the object's mileage property will be set to the value passed to constructor
b) the object's mileage property will not be set the value passed to constructor
c) error will occur because you have two declarations with the same variable name
c) error will occur because you have two declarations with the same variable name
If the input is 10, what is the output?
a) 14
b) 13
c) Syntax error in the x = x + z++ expression
d) 0
a) 14
What value of x outputs "Junior"?
a) Values 57 or larger
b) No such value
c) Values 55 or 57
d) Value 56
d) Value 56
This is how switch statement works:
The switch expression is evaluated once
The value of the expression is compared with the values of each Case.
If there is a match, the associated code block is executed. For example, if the value of the expression is 9, then case 9 will be executed. If the value of the expression is 10, then case 10 will be executed.
Break statement is executed to end the conditional checking and default is the default case if there are no cases that are equal to the value of the switch expression (similar to ELSE).
Now answer the following question. For what values of x does the default case execute in the code below? x is declared as an integer.
a) Only for value 5
b) Only for all values greater than 4
c) Only for values that are not 2, 3, or 4
d) For any value
c) Only for values that are not 2, 3, or 4
Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY.
a) w >= 100 / w = scnr.nextInt()
b) w < 100 / w = scnr.nextInt()
c) w < 100 / (nothing)
d) w >= 100 / (nothing)
b) w < 100 / w = scnr.nextInt()
A loop should output 1 to n in the format 12345..n. For example, if n is 5, the output is 12345. Based on the requirements, what should XXX and YYY be? Choices are in the form XXX / YYY.
a) i = 0; i < n / i
b) i = 1; i < n / i + 1
c) i = 0; i < n / i + 1
d) i = 1; i < n / i
c) i = 0; i < n / i + 1
What is the output?
a) 12
b) 18
c) 6
d) 0
b) 18
In the following class Student, which constructor would be called by the statement Student newStud = new Student("Tim", 14)?
a) Student()
b) Student(String s, int n)
c) Student(String s)
d) Student(int n, String s)
b) Student(String s, int n)
What is the value of hondaAccord's odometer at the end of main( )?
a) 100
b) 120
c) 30
d) 20
c) 30
What kind of method is incCount()?
a) Mutator method
b) Constructor
c) Accessor method
d) Static method
a) Mutator method
Which XXX is the proper default constructor (a default constructor will be used if no variables are passed during object creation to initialize the object)?
a) public Employee( ) {
double mySalary = 10000;
}
b) private Employee( ) {
mySalary = 10000;
}
c) public Employee(double salary) {
mySalary = salary;
}
d) public Employee( ) {
mySalary = 10000
d) public Employee( ) {
mySalary = 10000
A constructor must be public and must not declare new or existing variables a second time. A default constructor does not have any input parameters.
Which lines(s) are invalid?
a) Line A
b) Line B
c) Line C
d) Line A & Line B
e) Line A, B, & C
a) Line A
What is the value of:
patsQuiz [3], joesQuiz [3] , suesQuiz [3]?
a) 55, 55, 95
b) 95, 95, 95
c) 95, 55, 95
c) 95, 55, 95
Which statement is not valid?
a) Musician drummer0 = new Musician();
b) Musician drummer1 = new Drummer();
c) Drummer drummer3 = new Drummer();
d) Drummer drummer4 = new Musician();
e) All are valid
d) Drummer drummer4 = new Musician();
Suppose you want to declare an array that can
store both a Drummer and a Guitarist – which
array will allow this?
a) Drummer[ ] boomers = new Drummer[2];
b) Guitarist[ ] pluckers = new Guitarist[2];
c) Musician[ ] band = new Musician[2];
d) None of the above
c) Musician[ ] band = new Musician[2];
Which methods can be defined in the same class?
a) all of the methods can be declared in same class
b) methods 1 & 3 cannot be declared in same class
c) methods 2 & 4 cannot be declared in same class
d) only one of the methods can be declared in the class
b) methods 1 & 3 cannot be declared in same class
Create a getter
public type getVariableName() {
return variableName;
}
Create a toString
@Override
public String toString() {
String ouput = (“quote” + varialble + “quote”);
return ouput;
}
Create a constructor
public className(parameters) {
this.variable = variable;
}
Create a setter
public void setVariable( type variable) {
this.variable = variable;
}
Order these terms by the amount of bits they use, most to least
boolean
char
double
byte
float
long
short
int
boolean
byte
short / char
int / float
long / double
x += 1
x = x + 1
If operand 1 is a floating-point & operand 2 is an integer, what is operand 3’s type?
Floating pointI
Show an example of explicit conversion
int varA = (int) 2.4;
Is this a primative or reference type?
int userID = primitive
Primitive
Is this a primitve or reference type?
SportsCar yourCar;
Reference type
Class vehicle has:
Private fields modelName, productionYear, and color
Public methods setModelName, getModelName, and printDetails
What will an instance of Vehicle have by default?
All of these
Class vehicle has:
Private fields modelName, productionYear, and color
Public methods setModelName, getModelName, and printDetails
Car is an instance of vehicle which has all its traits and:
Private field numberOfDoors
Public method getNumberOfDoors and addMiles
What will an instance of car have?
All fields and methods of car, both those unique to it and those who come from vehilce
We have 3 classes; Car, SportsCar, and Tire. What has-a and is-a relationships can most likely be found between these given that SportsCar is a direct descendent of Car?
Has-A Relationships
•Car class and Tire class
•SportsCar class and Tire class
Is-A Relationships
•SportsCar is-a Car
What is the ouput of this code?
Musician musician = new Guitarist();
musician.play();
musician = new Drummer();
musician.play();
silence
silence
What is the output of this code?
Musician musician = new Guitarist();
musician.play();
twang
What is the ouput of this code?
Musician musician = new Guitarist();
musician.play();
musician = new Drummer();
musician.play();
twang
boom boom