PLEASE Help answer Java test review questions! 1) Which of the following stateme
ID: 3840559 • 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
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
please find the solution, explained each questions:
1)Which of the following statements about recursion are TRUE? Select all that apply.
correct option -> e), a)
Explanation -> A recursion happens when a method call itself.
Really if you have infinite memory then recursion can happens infinite if no interuption happened
2)Which of the things below are TRUE of the abstract keyword. Select all that apply.
correct answer -> f)
Explanation -> we cannot instaniate abstarct class as like interface in java
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): "
Correct Option-> b)
Explanation -> there is no any method getChar() in string API
we cannot cast String to character
getNext() return String so we cannot store in char
4) Match the following terms with the correct definition.
correct match should as per below
Question Selected Match
Java Language Specification D. defines the syntax of Java
API C. set of separate programs used to develop and test Java programs
JDK A. contains predefined classes and interfaces
IDE B.a graphical user interface for editing,
compiling, and debugging Java programs
5)Which of the following function headers is syntactically correct?
correct option -> d) public static void HeyListen (String Navi, int... fairies)
Explanation -> when we giving varargs parameter in method it must should be last parameter followed by more zero or more than zero parameter
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.
Correct option ->b)package statement
Explanation ->package statement always should be at top level, cant use import statement above package statement it should be like
package Hyrule;
import java.util.*;
7)Which of the following things are accomplished by the final keyword?
correct option -> a), b), g)
Explanation -> in java we cant modify the final value once declared, its like constant variable
We cant override final method, but we can overload final method.
we cant subclassed final class in java , when we mark a class as a final then it becomes immutable
in JDK "java.lang.String" is final class
8)Which of the following statements are TRUE of immutable objects? Select all that apply.
correct option -> a) , c)
Explanation -> we should not expose mutators for final variable and it should be always private
we can define final primitive variable but TC that of above lines
9)Which of the following statements are FALSE? Select all that apply.
correct option -> Declaring an array variable allocates space for the array in memory
Explanation -> when we declare an array it does not set allocate memory for the array.
The array must be created (allocate the memory) later before it can be referenced (used)
10)Which of the following code segments will produce a syntax error? Select all that apply.
correct option -> f), g)
Explanation -> here in code float potion = 3.5; int hearts = (int) potion
when we defining float variable with decimal then need to append 'd' as like float potion = 3.5d
or if variable doesnt have decimal then it is fine if define like float potion = 3// it will fine
we cant assign long value to int , you must have to cast.
you can assign int value to long , compiler not bother about this
11) Given the following code segment, what output would be generated?
correct option -> sorry, but here all option are incorrect
Explanation -> when you compile above code , compliler will throw exception as below:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unreachable catch block for IndexOutOfBoundsException.
It is already handled by the catch block for Exception"
Because exception already caught by catch(Exception ex)
it will never come down to catch (IndexOutOfBoundsException ex2)
because Exception class it the super class of IndexOutOfBoundsException class
12) Which of the following statements about interfaces are FALSE? Select all that apply.
correct option -> b), c), d), f)
Explanation -> Inteface cannot not be instaniated it onle can be referenced or implemented by concrete or abstarct class.
A class can implement multiple interface
cannot define static method in interface
All variable cannot be abstract not only in interface it this rule also implies on Abstarct class, normal class or in method.
Plelse comment if you have any doubts :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.