Missed Questions Flashcards
(double) (12/5) returns what?
- The cast is performed too late
Given that List doNothing(List list) simply returns “list” and is in class Test, what will happen in:
ArrayList nums = new ArrayList(); nums = Test.doNothing(nums)
doNothing returns a List, not an ArrayList, and you can’t assign a List object to an ArrayList variable. An ArrayList IS an List, however, so calling doNothing(ArrayList) IS valid.
Which algorithm provides the most efficient way of finding the largest of 2000 elements stored in an array (not necessarily sorted)?
Selection Sort (terminated after the first five iterations). Selection Sort sorts by finding the largest elements in the list, etc…
If an abstract class has no implemented constructors or methods, it is better to make it an _______
interface. All the advantages of inheritance are preserved, pus a class that implements the interface can potentially extend some other class
Can an abstract class extend another abstract class?
YES
Which of the following code segments correctly traverses a two-dimensional int array m, row by row?
A 2D array is implemented as a 1D array of its rows, where each row is a 1D array. Therefore, the elements of m have the type int[], not in.
Can an abstract class implement an interface?
YES
Can you declare an array of objects of an abstract class type, but not of an interface type?
NO
A method cannot take a parameter of an interface type nor abstract class type
TRUE
Object has neither ______ nor ______ method
substring, compareTo
when removing elements from a list, be careful using a standard loop because:
list.remove(i) shifts the subscripts of the subsequent elements down by one, so only every other element is removed.
In the GridWorld design, why is the Actor class not made abstract, with the act method abstract?
To be able to create Actor objects in GridWorld applications and explore their attributes and behavior. You cannot create an object of an abstract class.
Suppose an array contains 127 different random values arranged in ascending order, and a most efficient searching algorithm is used to find a target value. How many elements of the array will be examined when the target equals arr[39]?
- Binary search will look at arr[63], arr[31], arr[47], arr[39]
Assuming a and b are Boolean variables, what is the same thing as the following:
!(!a || b) || (!a && b)
= (a && !b) || (!a && b). This evaluates to true if and only if a and b have different values.
A project needs two related classes, X and Y. A programmer has decided to provide an abstract class A and derive both X and Y from A rather than implementing X and Y completely independently of each other. Which of the following is nOT a valid rationale for this design decision.
Being able to cast objects of type X into Y and vice-versa. This is NOT a good idea. They are both different animals, and both merely extend a super class, but NOT each other.
If Game is an interface and Fun a class, then:
Game game = fun; is _____
an indication that Fun implements Game. You CANNOT instantiate (make objects of) an interface. Game game = new Game(); is NOT legal code. You can, however, refer to an object that implements an interface by the type of the interface.
Integer.MAX_VALUE is determine by ____
the size of int, which is ALWAYS 4 bytes, no matter the platform that Java is running. Java source code is compiled into bytecodes, which may then be run on any computer that has a Java Virtual Machine installed.
How to compare if two strings hold the same values?
str1.equals(str2) OR str1.compareTo(str2)
A class does not NEED to define a ________
constructor. If it does not, then Object’s is called
When overriding Object’s equals method, the input to the function must be of type _____
Object