Cisc181 Midterm Practice Questions

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards
<p>What is the value of valOne after these lines are executed?</p><p></p><p>a) 0.5</p><p>b) 0</p><p>c) 0.0</p><p>d) none of the above</p>

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

2
New cards
<p>What is the value of valTwo after these lines are executed?</p><p></p><p>a) 0.5</p><p>b) 0</p><p>c) 0.0</p><p>d) none of the above</p>

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

3
New cards
<p>What is displayed after the main method is executed?</p><p></p><p>a) Student Age is 24</p><p>b) Student Age is 231</p><p>c) Student Age is userAge + 1</p>

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

4
New cards

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

5
New cards
<p>What are the values assigned to each variable after the following code is executed?</p>

What are the values assigned to each variable after the following code is executed?

a = 4

b = 2.5

c = 15

d = 5.5

6
New cards
<p>What is the value of the following boolean expression if a = true and b = false?</p><p></p><p>a) true</p><p>b) false</p>

What is the value of the following boolean expression if a = true and b = false?

a) true

b) false

a) true

7
New cards
<p>What is y after executing the statements?</p><p></p><p>a) 12</p><p>b) 10</p><p>c) 8</p><p>d) 6</p>

What is y after executing the statements?

a) 12

b) 10

c) 8

d) 6

b) 10

8
New cards
<p>What will be the value of x after executing the following code?</p><p></p><p>a) 6</p><p>b) 5</p><p>c) 8</p><p>d) 7</p>

What will be the value of x after executing the following code?

a) 6

b) 5

c) 8

d) 7

c) 8

9
New cards
<p>What is the output of the following code snippet?</p><p></p><p>a) 7.5</p><p>b) 5</p><p>c) 7</p><p>d) Compilation Error</p>

What is the output of the following code snippet?

a) 7.5

b) 5

c) 7

d) Compilation Error

c) 7

10
New cards

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

11
New cards
<p>Which XXX completes the code to check for and read in doubles from the file, "myScores.txt"?</p><p></p><p>a) scnr.hasNext()</p><p>b) scnr.hasNextDouble()</p><p>c) hasNextDouble()</p><p>d) hasNextLine()</p>

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()

12
New cards
<p>What is the value of y that will be printed?</p><p></p><p>a) 5</p><p>b) 3</p><p>c) 0</p><p>d) 6</p>

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

13
New cards
<p>What is the value of the variable ‘result’?</p><p></p><p>a) 3</p><p>b) 2.25</p><p>c) 2</p><p>d) Error: The operands are different types and cannot be divided</p>

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.

14
New cards

In JAVA, which keyword is used to implement a decision-making statement?

a) if

b) decide

c) case

d) select

a) if

15
New cards

In Java, which of the following is NOT a valid variable name?

a) $variableName

b) 1stVariable

c) variableName

b) 1stVariable

16
New cards

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;

17
New cards
<p>Suppose you are designing a class called Circle. Which of the following is the best way to define its members?</p>

Suppose you are designing a class called Circle. Which of the following is the best way to define its members?

knowt flashcard image
18
New cards
<p>Suppose you are designing a class called Circle. Which access modifiers should be used for its members?</p>

Suppose you are designing a class called Circle. Which access modifiers should be used for its members?

knowt flashcard image
19
New cards
<p>What will happen when we create an instance using this constructor?</p><p></p><p>a) the object's mileage property will be set to the value passed to constructor</p><p>b) the object's mileage property will not be set the value passed to constructor</p><p>c) error will occur because you have two declarations with the same variable name</p>

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

20
New cards
<p><span>If the input is 10, what is the output?</span></p><p></p><p></p><p><span>a) 14</span></p><p><span>b) 13</span></p><p><span>c) </span>Syntax error in the x = x + z++ expression </p><p>d) 0</p>

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

21
New cards
<p><span>What value of x outputs "Junior"?</span></p><p></p><p>a) Values 57 or larger</p><p>b) No such value</p><p>&nbsp;c) Values 55 or 57</p><p>d) Value 56</p>

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

22
New cards
<p>This is how switch statement works:</p><p>The switch expression is evaluated once</p><p>The value of the expression is compared with the values of each Case. </p><p>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.</p><p>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).</p><p>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.</p><p></p><p>a) Only for value 5</p><p>b) Only for all values greater than 4</p><p>c) Only for values that are not 2, 3, or 4</p><p>d) For any value</p>

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

23
New cards
<p>Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY.</p><p></p><p>a) w &gt;= 100  /   w = scnr.nextInt()</p><p>b) w &lt; 100  /   w = scnr.nextInt()</p><p>c) w &lt; 100   /  (nothing)</p><p>d) w &gt;= 100  /  (nothing)</p>

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()

24
New cards
<p><span>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.</span></p><p></p><p><span>a) </span>i = 0; i &lt; n  /  i</p><p>b) i = 1; i &lt; n  /  i + 1</p><p>c) i = 0; i &lt; n  /  i + 1</p><p>d) i = 1; i &lt; n  /  i</p>

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

25
New cards
<p>What is the output?</p><p></p><p>a) 12</p><p>b) 18</p><p>c) 6</p><p>d) 0</p>

What is the output?

a) 12

b) 18

c) 6

d) 0

b) 18

26
New cards
<p>In the following class Student, which constructor would be called by the statement Student newStud = new Student("Tim", 14)?</p><p></p><p>a) Student()</p><p>b) Student(String s, int n)</p><p>c) Student(String s)</p><p>d) Student(int n, String s)</p>

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)

27
New cards
<p><span>What is the value of hondaAccord's odometer at the end of main( )?</span></p><p></p><p><span>a) 100</span></p><p><span>b) 120</span></p><p><span>c) 30</span></p><p><span>d) 20</span></p>

What is the value of hondaAccord's odometer at the end of main( )?

a) 100

b) 120

c) 30

d) 20

c) 30

28
New cards
<p>What kind of method is incCount()?</p><p></p><p>a) Mutator method</p><p>b) Constructor</p><p>c) Accessor method</p><p>d) Static method</p>

What kind of method is incCount()?

a) Mutator method

b) Constructor

c) Accessor method

d) Static method

a) Mutator method

29
New cards
<p>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)?</p><p></p><p>a) public Employee( ) {</p><p>   double mySalary = 10000;</p><p>}</p><p>  </p><p>b) private Employee( ) {</p><p>   mySalary = 10000;</p><p>}</p><p>  </p><p>c) public Employee(double salary) {</p><p>   mySalary = salary;</p><p>}</p><p></p><p>d) public Employee( ) {</p><p>   mySalary = 10000</p>

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.

30
New cards
<p>Which lines(s) are invalid?</p><p></p><p>a) Line A</p><p>b) Line B</p><p>c) Line C</p><p>d) Line A &amp; Line B</p><p>e) Line A, B, &amp; C</p>

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

31
New cards
<p>What is the value of:</p><p>patsQuiz [3], joesQuiz [3] , suesQuiz [3]?</p><p></p><p>a) 55, 55, 95</p><p>b) 95, 95, 95</p><p>c) 95, 55, 95</p>

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

32
New cards
<p>Which statement is not valid?</p><p></p><p>a) Musician drummer0 = new Musician();</p><p>b) Musician drummer1 = new Drummer();</p><p>c) Drummer drummer3 = new Drummer();</p><p>d) Drummer drummer4 = new Musician();</p><p>e) All are valid</p>

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();

33
New cards
<p>Suppose you want to declare an array that can</p><p>store both a Drummer and a Guitarist – which</p><p>array will allow this?</p><p></p><p>a) Drummer[ ] boomers = new Drummer[2];</p><p>b) Guitarist[ ] pluckers = new Guitarist[2];</p><p>c) Musician[ ] band = new Musician[2];</p><p>d) None of the above</p>

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];

34
New cards
<p>Which methods can be defined in the same class?<br><br>a) all of the methods can be declared in same class</p><p>b) methods 1 &amp; 3 cannot be declared in same class</p><p>c) methods 2 &amp; 4 cannot be declared in same class</p><p>d) only one of the methods can be declared in the class</p>

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

35
New cards

Create a getter

public type getVariableName() {

return variableName;

}

36
New cards

Create a toString

@Override

public String toString() {

String ouput = (“quote” + varialble + “quote”);

return ouput;

}

37
New cards

Create a constructor

public className(parameters) {

this.variable = variable;

}

38
New cards

Create a setter

public void setVariable( type variable) {

this.variable = variable;

}

39
New cards

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

40
New cards

x += 1

x = x + 1

41
New cards

If operand 1 is a floating-point & operand 2 is an integer, what is operand 3’s type?

Floating pointI

42
New cards

Show an example of explicit conversion

int varA = (int) 2.4;

43
New cards

Is this a primative or reference type?

int userID = primitive

Primitive

44
New cards

Is this a primitve or reference type?

SportsCar yourCar;

Reference type

45
New cards

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

46
New cards

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

47
New cards

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

48
New cards
<p>What is the ouput of this code?</p><p></p><p>Musician musician = new Guitarist();</p><p>musician.play();</p><p>musician = new Drummer();</p><p>musician.play();</p>

What is the ouput of this code?

Musician musician = new Guitarist();

musician.play();

musician = new Drummer();

musician.play();

silence

silence

49
New cards
<p>What is the output of this code?</p><p></p><p>Musician musician = new Guitarist();</p><p>musician.play();</p>

What is the output of this code?

Musician musician = new Guitarist();

musician.play();

twang

50
New cards
<p>What is the ouput of this code?</p><p></p><p>Musician musician = new Guitarist();</p><p>musician.play();</p><p>musician = new Drummer();</p><p>musician.play();</p>

What is the ouput of this code?

Musician musician = new Guitarist();

musician.play();

musician = new Drummer();

musician.play();

twang

boom boom