PLEASE Help answer Java test review questions! 1) Which of the following stateme
ID: 3842681 • Letter: P
Question
PLEASE Help answer Java test review questions!
1) Which of the following statements about recursion are TRUE? Select all that apply.
a)Infinite recursion could happen if there were an infinite amount of memory available
b)Recursive solutions are always simpler than iterative solutions
c)Every solution that can be solved by using loops can also be solved recursively
d)Recursion involves the repeated execution of a segment of code.
e)Recursion only happens when a function calls itself
f) There are no drawbacks to using recursion.
2)
Which of the things below are TRUE of the abstract keyword. Select all that apply.
a)prevents a class from being extended
b)prevents a subclass from overriding the abstract method
c)prevents a class from defining constructors
d)prevents a method from being defined in the class
e)prevents the class from being used as a data type
f)prevents a class from being instantiated
3)
Given the code below, which of the following statements will properly read a character from the keyboard.
Scanner OldMan = new Scanner(System.in);
System.out.println("It is dangerous to go alone. Take this? (Y/N): "
a)String yesno = OldMan.next();
char answer = (char)yesno;
b)String yesno = OldMan.next();
char answer = yesno.charAt(0);
c)char answer = OldMan.nextChar();
d)char answer = OldMan.getNext();
4)
Match the following terms with the correct definition.
Question
Selected Match
Java Language Specification
D.
defines the syntax of Java
API
F.
used to develop server-side applications
JDK
A.
contains predefined classes and interfaces
IDE
B.
a graphical user interface for editing, compiling, and debugging Java programs
A.
contains predefined classes and interfaces
B.
a graphical user interface for editing, compiling, and debugging Java programs
C.
set of separate programs used to develop and test Java programs
D.
defines the syntax of Java
E.
used to develop applications for mobile devices
F. used to develop server-side applications
5)
Which of the following function headers is syntactically correct?
a)public static void HeyListen (int... fairies, String... Navi)
b)public static int... HeyListen (int fairies, String Navi)
c)public static void HeyListen (int... fairies, String Navi)
d)public static void HeyListen (String Navi, int... fairies)
6)
Examine the following source code. Assume this is a complete file named Epona.java. Which of the items below would be treated as a syntax error when compiling the code? Select all that apply.
import java.util.*;
package Hyrule;
public class Epona
{
void setGallopSpeed(int x)
{ gallopSpeed = x; }
static private int gallopSpeed;
private double weight;
public void speedUp()
{ this.speedUp(10); }
public void speedUp(int x)
{ this.setGallopSpeed(x); }
}
a)lack of access specifiers for function
b)package statement
c)importing an unused library
d)use of static for variables
e)placement of class variables
f)use of this to call overloaded function
g)use of this to call a non-overloaded function
7)
Which of the following things are accomplished by the final keyword?
a)prevents a variable from being modified
b)prevents a method from being overridden
c)prevents a method from being overloaded
e)prevents an interface from being implemented
f)initiates the last iteration of a loop
g)prevents a class from being extended
8)
Which of the following statements are TRUE of immutable objects? Select all that apply.
a)There cannot be any mutator methods for the class variables
b)The class variables must be of a primitive data type
c)All class variables must be private
d)All class methods must be static
e)Accessor methods cannot return a class variable reference to an object that can be modified
f)The class must be declared as abstract
9)
Which of the following statements are FALSE? Select all that apply.
a)When space for an array is allocated, each element is assigned a default value.
b)Declaring an array variable allocates space for the array in memory
c)An array can be created without explicitly stating the size of the array
d)When used with an array variable, the assignment operator (array1 = array2) creates a deep copy.
e)Non-constant values can be used to declare the size of an array.
f)Arrays can be returned from a function
10)
Which of the following code segments will produce a syntax error? Select all that apply.
a)int hearts = 3;
hearts += 2.5;
b)char letter = 'L';
System.out.println((char)((int)letter));
c)String rupees = '1' + "00";
d)char letter = 'Z';
e)if (letter >= 'A' && letter <= 'Z')
System.out.println(letter + "elda");
f)float potion = 3.5;
int hearts = (int) potion;
g)long sword = 10;
int arrow = sword;
11) Given the following code segment, what output would be generated?
int rupees = 500;
String [] inventory = new String[10];
try
{
inventory[10] = "Deku Mask";
rupees -= 100;
}
catch (Exception ex)
{ rupees += 100; }
catch (IndexOutOfBoundsException ex2)
{ rupees -= 200; }
finally
{ rupees += 300; }
System.out.println(rupees);
a)600
b)800
c)900
d)700
12)
Which of the following statements about interfaces are FALSE? Select all that apply.
a)all methods are public
b)the interface can be instantiated by using the new keyword
c)only one interface can be implemented per class
d)all methods are static
e)access specifiers are optional when declaring the interface members
f)all variables in the interface are abstract
g)all methods are abstract
Explanation / Answer
1.The Statements about Recursion are TRUE:-
a)Infinite recursion could happen if there were an infinite amount of memory available
b)Recursive solutions are always simpler than iterative solutions
c)Every solution that can be solved by using loops can also be solved recursively
d)Recursion involves the repeated execution of a segment of code.
e)Recursion only happens when a function calls itself
Explanation:-
There are some drawbacks to using recursion.
Recursion may use more memory than an Iteration.
2.The Things about the Abstract keyword are TRUE:-
f)prevents a class from being instantiated
Explanation:-
Because is not fully implemented the class, it contains abstract method it cannot be executed.
If compiler allows us to create the object for the abstract class, we can invoke the abstract method using that object which cannot be executed by JVM at runtime. Hence to restrict us calling abstract methods compiler does not allow us to instantiate an abstract class.
3.The Statements will properly read a character from the keyboard:-
Scanner OldMan = new Scanner(System.in);
System.out.println("It is dangerous to go alone. Take this? (Y/N): "
b)String yesno = OldMan.next();
char answer = yesno.charAt(0);
Explanation:-
There is no straight method to get a character from the Scanner. So initially we have to get the String by using scanner.next() and then call String.charAt(0) method on the returned String.
4.The Terms with the correct definition:-
a.Java Language Specification - Defines the syntax of Java.
b.API - Contains Predefined classes and interfaces.
c.JDK - Used to develop server-side applications.
d.IDE - A Graphical User Interface for editing, compiling, and debugging Java programs.
5.The function headers which are syntactically correct:-
d)public static void HeyListen (String Navi, int... fairies)
7.The Things are accomplished by the final keyword:-
a)prevents a variable from being modified
b)prevents a method from being overridden
g)prevents a class from being extended
Explanation:-
*The moment the final members are declared as final members explicitly by using the final keyword then the final class members are final.
* The final method cannot be overridden in the subclass, if we try to override compiler will throw an error.
* If we do not want to extend our class functionality we must define the class as final.
8.The Things about the Abstract keyword are FALSE:-
c)An array can be created without explicitly stating the size of the array.
Explanation:-
* We must specify array size. If we do not specify array size it leads to compile time error - Array Dimension Missing.
10.The code segments will produce a syntax error:-
e)if (letter >= 'A' && letter <= 'Z')
System.out.println(letter + "elda");
f)float potion = 3.5;
int hearts = (int) potion;
Explanation:-
* The Source type range must be less than or equals to destination type range, otherwise, it leads to compile time error-possible loss of precision.
g)long sword = 10;
int arrow = sword;
Explanation:-
* The Source type range must be less than or equals to destination type range, otherwise, it leads to compile time error-possible loss of precision.
12.The Statements about Interfaces are FALSE:-
b.The Interface can be instantiated by using the new keyword.
d)all methods are static
g)all methods are abstract
Explanation:-
* Interface can not be instantiated.
* By default interface variables are public static final variables.
* By default interface methods are public abstract methods.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.