unit 8

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A method that has no implementation is called a/an ____ method. interface implementation overloaded abstract

abstract

All methods located inside of an interface are automatically labeled with which of the following modifiers? static abstract final protected interface

abstract

A class can implement how many other interfaces? 0 1 2 as many as you want A and D only

as many as you want

An interface can extend how many other interfaces? 0 1 2 as many as you want A and D only

as many as you want

Which of the following could fill <blank 1>? public interface Testable { <blank 1> } double getScore(); public double getScore(); public abstract double getScore(); A and B only A, B, and C

A, B, and C

int[][] ticketInfo = {25,20,25}, {25,20,25}; String[][] seatingInfo = {"Jamal", "Maria"}, {"Jake", "Suzy"}, {"Emma", "Luke"}; int value = ticketInfo[1][0]; String name = seatingInfo[0][1]; What is the value of name after the code above executes? A) Suzy B) Maria C) Jake D) Jamal E) Emma

B) Maria

Which of the following is the correct way to add 2 between the 1 and 3 in the following list nums = [1, 3, 4]? A) nums.add(2, 1); B) nums.add(1, 2); C) nums.add(2, 2); D) nums.add(0, 2); E) nums.add(2, 0);

B) nums.add(1, 2);

Which index is the last element in an arraylist called nums at? A) nums.length - 1 B) nums.size() - 1 C) nums.size D) nums.length

B) nums.size() - 1

All variables located inside of an interface are automatically labeled with which of the following modifiers? static abstract final A and C only C only

A and C only

An interface can extend how many other classes? 0 1 2 as many as you want A and D only

0

A class that implements Comparable has to at least have how many methods? public interface Comparable { public abstract int compareTo(); } 0 1 2 3 4

1

What is the minimum number of methods a class extending abstract class Demo could have? public abstract class Demo { public Demo() { } public abstract String destroy(); public String toString() { return "--"; } } 0 1 2 3 4

1

What is the minimum number of methods a class extending abstract class Demo could have? public abstract class Demo { public abstract String destroy(); } 0 1 2 3 4

1

How many rows does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?

2

A class that implements Locatable has to at least have how many methods? public interface Locatable { int getX(); int getY(); double getSpeed(); } 0 1 2 3 4

3

How many columns does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?

4

ticketInfo = new int [2][3]; seatingChart = new String [3][2]; How many elements are in ticketInfo?

6

Given the following code segment, what is the value of sum after this code executes? int[][] matrix = {1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}; int sum = 0; int col = matrix[0].length - 2; for (int row = 0; row < 4; row++) { sum = sum + matrix[row][col]; }

8

Which of the following statements about abstract classes is NOT true? A class that inherits an abstract method and does not override it must be declared as abstract. A class cannot be declared as abstract if it has no abstract methods. You cannot instantiate an object from an abstract class. You can construct a variable whose type is an abstract class.

A class cannot be declared as abstract if it has no abstract methods.

Which of the following is the correct way to remove the value 3 from the list nums = [5, 3, 2, 1]? A) nums.remove(1); B) nums.remove(3); C) nums.remove(2); D) nums.remove(new Integer(3));

A) nums.remove(1);

Which of the following could fill <blank 1>? public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { private int xPos, yPos; private double speed; <blank 1> Ship() { //code not shown } public Ship(int x, int y, double s) { xPos=x; yPos=y; speed=s; } <blank 2> int getX() { return xPos; } <blank 2> int getY() { return yPos; } <blank 2> double getSpeed() { return speed; } } //code in the main method of another class <blank 3> public protected private abstract A, B, and C

A, B, and C

A class from which you cannot create objects is called a/an ____. Abstract class. Concrete class. Non-inheritable class. Static class.

Abstract class.

A class that cannot be instantiated is called a/an ____. Abstract class. Anonymous class. Concrete class. Non-inheritable.

Abstract class.

Which of the following statements about abstract methods is true? An abstract method has a name, parameters, and a return type, but no code in the body of the method. An abstract method has parameters, a return type, and code in its body, but has no defined name. An abstract method has a name, a return type, and code in its body, but has no parameters. An abstract method has only a name and a return type, but no parameters or code in its body.

An abstract method has a name, parameters, and a return type, but no code in the body of the method.

int[][] ticketInfo = {25,20,25}, {25,20,25}; String[][] seatingInfo = {"Jamal", "Maria"}, {"Jake", "Suzy"}, {"Emma", "Luke"}; What is the value at seatingInfo[2][1] after the code above executes? A) Emma B) Luke C) Jake D) Maria E) Suzy

B) Luke

Which of the following statements about abstract classes and interfaces is NOT true? Abstract classes can have instance variables but interfaces cannot. Both abstract classes and interfaces can have instance variables. Abstract classes can have concrete methods but interfaces cannot. Abstract classes can have constructors but interfaces cannot.

Both abstract classes and interfaces can have instance variables.

Which of the following sets the value for the 3rd row and 2nd column of a 2D array called nums? A) nums[2][3] = 5; B) nums[1][2] = 5; C) nums[2][1] = 5; D) nums[3][2] = 5;

C) nums[2][1] = 5;

How would you get the value 6 out of the following array int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};? A) a[3][1] B) a[0][3] C) a[2][0] D) a[0][2] E) a[1][3]

D) a[0][2]

Which of the following is the correct way to get the first value in a list called nums? A) nums.first() B) nums[1] C) nums.get(1) D) nums.get(0) E) nums[0]

D) nums.get(0)

Which of the following is the correct way to set the second value in a list called nums to 5? A) nums.set(2, 5); B) nums[2] = 5; C) nums.set(5, 1); D) nums.set(1, 5); E) nums[1] = 5;

D) nums.set(1, 5);

Which of the following could fill blank < *1 > ? public abstract class Theory { < *1 > } I. public Theory(int x){ } II. private Theory(int x){ } III. public final Theory(int x){ } I only II only I and II only I and III only I, II, and III only

I and II only

Which of the following could fill blank < *1 > ? public abstract class Theory { public int f(int x){ return 2 * x; } public < *1 > int g(int x); } I. abstract II. final III. static I only II only III only I and II only II and III only

I only

Which of the following could fill blank < *1 > ? public abstract class Theory { < *1 > } I. public Theory(int x){ } II. public int go(int x){ return x*5; } III. private int stop(){ return 887; } I only II only I and II only I and III only I, II, and III only

I, II, and III only

Which of the following could fill blank < *1 > ? public abstract class Theory { public < *1 > int HAL=9000; public int f(int x){ return 2 * x; } } I. abstract II. final III. static I only II only III only I and II only II and III only

II and III only

Assuming <blank 1> is filled correctly, which of the following could fill <blank 3>? public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { private int xPos, yPos; private double speed; <blank 1> Ship() { //code not shown } public Ship(int x, int y, double s) { xPos=x; yPos=y; speed=s; } <blank 2> int getX() { return xPos; } <blank 2> int getY() { return yPos; } <blank 2> double getSpeed() { return speed; } } //code in the main method of another class <blank 3> Locatable x = new Locatable(); Ship w = new Ship(3,5); Locatable s = new Ship(3,5,7.8); Ship w = new Locatable(3,5,7.8); Locatable s = new Ship(3.5,5,7);

Locatable s = new Ship(3,5,7.8);

A class that inherits an abstract method but does not override it ____. Cannot be inherited by other classes. Must be declared as an abstract class. Can have objects instantiated from it. Must be declared as an anonymous class.

Must be declared as an abstract class.

If a class has an abstract method, which of the following statements is NOT true? You can construct an object from this class. You cannot construct an object from this class. You cannot inherit from this class. All non-abstract subclasses of this class must implement this method.

You can construct an object from this class.

Which of the following statements about abstract classes is NOT true? You can declare a class as abstract only when it contains all abstract methods. You can declare a class as abstract if it contains some abstract methods. You cannot instantiate an abstract class. You must declare a class as abstract if it inherits an abstract method without overriding it.

You can declare a class as abstract only when it contains all abstract methods.

What type of variable is variable s? public interface Skeleton { String s = "Check it Yo!"; } instance class argumentative private self

class

Which of the following could fill <blank 1>? public interface Variable { <blank 1> } int x; int x = 9.6; double y = 99; B and C only A, B, and C

double y = 99;

Which of the following could fill <blank 1>? public interface Variable { <blank 1> } final int x; final int x = 9.6; final double y = 99; B and C only A, B, and C

final double y = 99;

An interface can extend another _________________ . abstract class class interface A and B A, B, and C

interface

int[][] ticketInfo; String[][] seatingChart; What is printed when you type System.out.println(ticketInfo); after you do the above declarations?

null

Which of the following could not fill <blank 1>? public interface Testable { <blank 1> } private void setScore(double s); void setScore(double s); abstract void setScore(double s); A and B only A, B, and C

private void setScore(double s);

All methods located inside of an interface are automatically set with what access? public private protected A and B only A, B, and C

public

All variables located inside of an interface are automatically set with what access? public private protected A and B only A, B, and C

public

Assuming <blank 1> is filled correctly, which of the following could fill <blank 2>? public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { private int xPos, yPos; private double speed; <blank 1> Ship() { //code not shown } public Ship(int x, int y, double s) { xPos=x; yPos=y; speed=s; } <blank 2> int getX() { return xPos; } <blank 2> int getY() { return yPos; } <blank 2> double getSpeed() { return speed; } } //code in the main method of another class <blank 3> public protected private abstract A, B, and C

public


Kaugnay na mga set ng pag-aaral

MGMT 4953: Reward/Compensation Exam 1

View Set

AP Psychology: Unit 4 - Learning

View Set