Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE Help answer Java test review questions! 1) Which of the following stateme

ID: 3843892 • 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

2)

Which of the things below are TRUE of the abstract keyword. Select all that apply

Answers : d,e,f are correct answers

Because Abstract keyword can be applied to class as well as methods. When it is applied to class, it cannot be instantiated but can be extended. Whenever abstract class is extended, its desperate to overrise all abstract methods. It does not allow class to create as a type. Abstract method cant be defined in a class.

public abstract class Electricity{

public abstract void payBill(double units);

void display(){

System.out.println("EPDCL");

}

}

3)

Given the code below, which of the following statements will properly read a character from the keyboard.

Answer: b is correct answer

b)String yesno = OldMan.next();

char answer = yesno.charAt(0);

Because in String first character i.e 0th position character is character. So, charAt(0) will be correct way to read chartacter in Java.

5)

Which of the following function headers is syntactically correct?

Answer: d is right answer

d)public static void HeyListen (String Navi, int... fairies)

Because,The variable argument type int fairies of the method HeyListen must be the last. It is allowed in Java.

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.

Answer : b is right answer, because package should be declared at the starting of program instead of creating after import statements.

7)

Which of the following things are accomplished by the final keyword?

Answers: a,b,g are right answers. Because, final is akeyword represents cannot be changed or modified for variable. It wont allow the features modified in the sub class and also cant reuse the functionalities of parent class.

8) Which of the following statements are TRUE of immutable objects? Select all that apply.

Answer : c) All class variables must be private

9) Which of the following statements are FALSE? Select all that apply.

Answers :

c)An array can be created without explicitly stating the size of the array

e)Non-constant values can be used to declare the size of an array.

10)

Which of the following code segments will produce a syntax error? Select all that apply.

Answer: e,f,g are correct answers

e option needs letter to be initialized to a specifi value. if letter is 'Z' it is right answer. Since option d seperates from option 'e', option e is wrong answer.

Also f and g are sytatically wrong because, option "f" cannot convert double to float, it needs float precision like float potion=3.5f

Aldo g is syntatically wrong because, cannot convert from long to int value.

long sword = 10;
int arrow = (int) sword;

The above will be right syntax.

11) Given the following code segment, what output would be generated?

Answer: There is no answer in the given options, because, it leads to a syntatical error called "Unreachable catch block for IndexOutOfBoundsException. It is already handled by the catch block for Exception". It means, the super Exception class is catched in the catch block prior to sub class Exception so, hierarchy is follwed. If exceptions follow right priority, then output is 900

12)

Which of the following statements about interfaces are FALSE? Select all that apply.

Answers: b,c,d, f are false statements. Because Interface is collection of public static final variables and public abstract methods by default. So, all the above statements ruled out from the given hypothesis.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote