Question: ANY HELP PLEASE !!!! Question 1 Assuming a StringIndexOutOfBoundsException exception class exists, what is the output of this code sequence? try { String word =
ANY HELP PLEASE !!!!
Question 1
Assuming a StringIndexOutOfBoundsException exception class exists, what is the output of this code sequence?
try
{
String word = new String("Java");
System.out.println( word.charAt( 4 ) );
}
catch( StringIndexOutOfBoundsException e )
{
System.out.println( OOPS! );
}
finally
{
System.out.println( OOPS! again );
}
| a. |
OOPS! | |
| b. |
a OOPS! again | |
| c. |
a | |
| d. |
OOPS! OOPS! again |
2.5 points
Question 2
In the method header public static void main( String [ ] args )
| a. |
variable identifier args is an array of type String | |
| b. |
variable identifier args could contain arguments passed to method main from the command line | |
| c. |
Both a and b | |
| d. |
None of the above |
2.5 points
Question 3
In a typical class, what is the general recommendation for access modifiers?
| a. |
Instance variables are are private and methods are private | |
| b. |
Instance variables are private and methods are public | |
| c. |
Instance variables are public and methods are private | |
| d. |
Instance variables are public and methods are public |
2.5 points
Question 4
What is the output of the following code sequence:
double a = 27 % 11; System.out.println( a );
| a. | 297.0 | |
| b. | 2.0 | |
| c. | 5.0 | |
| d. | 2.45 |
2.5 points
Question 5
In the Quiz class, the foo method has the following API:
public static double foo( int i)
Assuming x is an integer value, and assuming the following statement having been executed:
Quiz q = new Quiz();
which method call(s) could be used?
| a. |
double i = Quiz.foo( x ); | |
| b. |
System.out.println( Foo has returned the double value: + q.foo( x)); | |
| c. |
both a and b | |
| d. |
neither a or b |
2.5 points
Question 6
To instantiate an object reference named d1 of class SimpleDate assuming the following constructor method headers:
public SimpleDate() public SimpleDate( int mm, int dd, int yyyy )
Which statement(s) would be valid and sufficient to instantiate an object of type SimpleDate:
| a. |
SimpleDate d1; | |
| b. |
SimpleDate d1 = new SimpleDate(); | |
| c. |
SimpleDate d1; d1 = new SimpleDate( 7, 4, 1776); | |
| d. |
b and c |
2.5 points
Question 7
What is the output of the following code sequence?
int dice = 5;
switch ( dice ) { case 1: System.out.println( One); break; case 2: case 3: System.out.println( Two or Three); break; case 4: System.out.println( Four); break; case 5: case 6: System.out.println( Five or better); break; default: System.out.println( Off the chart); } System.out.println( Exit Switch );
| a. | Five or better Off the chart Exit Switch
| |
| b. |
Exit Switch | |
| c. | Five or better Exit Switch | |
| d. | Five or better Off the chart |
2.5 points
Question 8
What are the values of i and product after this code sequence is executed?
int i = 6; int product = 1; do {
product *= i; i++;
} while (i < = 9 );
| a. | i is 9 product is 3024 | |
| b. | i is 9 product is 336 | |
| c. | i is 10 product is 336 | |
| d. | i is 10 product is 3024 |
2.5 points
Question 9
Given the following code declaring and initializing three boolean variables x, y and z with respective values false, false, and false, answer question 9 indicating whether the value of the expression is true or false.
boolean x = false; boolean y = false; boolean z = false;
Expression: x || !z
True
False
2.5 points
Question 10
What is the output of this code sequence?
boolean x = true; boolean y = false; for ( int i = 0; i < 2; i++)
System.out.println( Hello );
if( x && y)
System.out.println( Done );
else
System.out.println( Shall we go sailing? );
| a. | Hello Hello Shall we go sailing? | |
| b. | Hello Hello Hello Shall we go sailing? | |
| c. | Hello Hello Hello Done | |
| d. | Hello Done Hello Done Hello Done |
2.5 points
Question 11
What are the values of i and sum after this code sequence is executed?
int i = 0; int sum = 0; for ( i = 0; i < = 40; i++) {
if ( i % 10 = = 0)
sum += i ;
}
| a. | i is 40 sum is 60 | |
| b. | i is 41 sum is 60 | |
| c. | i is 40 sum is 100 | |
| d. |
i is 41 sum is 100 |
2.5 points
Question 12
What is the output of the following code sequence:
double a = 16 / 5; System.out.println( a );
| a. | 2.6 | |
| b. | 3.2 | |
| c. | a | |
| d. | 3.0 |
2.5 points
Question 13
Given code:
public abstract class A{ } public class B extends A { }
The following code sequence would correctly create an object reference of class A holding an object reference for an object of class B:
A c; c = new B();
True
False
2.5 points
Question 14
Given the following code declaring and initializing two int variables x and y with respective values 7 and 9, answer question 14 indicating whether the value of the expression is true or false.
int x = 7; int y = 9;
Expression: ( y x == 0 || ( x + 2 ) != y)
True
False
2.5 points
Question 15
Class SimpleDate encapsulates integer instance variables month, day and year. Consider the following equals method in class SimpleDate:
public boolean equals( Object o ) { if ( !( d instanceof SimpleDate ) )
return false;
( Insert appropriate code from selections below)
if ( month == d1.month
&& day == d1.day && year == d1.year )
return true;
else
return false;
}
Which statement(s) could be used to complete the above method body code correctly?
| a. | SimpleDate d1; d1 = (SimpleDate)o; | |
| b. |
SimpleDate d1 = o; | |
| c. |
SimpleDate d1 = (SimpleDate)o; | |
| d. |
Both a and c |
2.5 points
Question 16
Which of the following is not a valid wrapper class?
| a. | Integer | |
| b. | Double | |
| c. | Char | |
| d. | Boolean |
2.5 points
Question 17
What is the output of this code sequence:
double [ ][ ] a =
{{ 12.5, 48.3, 65.0, 77.1 }, { 65.0, 48.3, 12.5}};
System.out.println( a[1][ 3 ] );
| a. |
An ArrayIndexOutOfBounds exception would be thrown. | |
| b. |
77.1 | |
| c. |
65.0 | |
| d. |
12.5 |
2.5 points
Question 18
What is the output of this code sequence?
double [ ] [ ] a =
{{ 100.4, 99.6, 48.2, 65.8 }, { 100.5, 99.7, 48.2, 65.8 }};
double temp = a[0][1];
for ( int i = 1; i < a.length; i++ )
for ( int j = 1; j < a[i].length; j++ )
{
if ( a[i][j] > temp )
temp = a[i][j];
}
System.out.println( temp );
| a. | 99.6 | |
| b. | 100.4 | |
| c. | 99.7 | |
| d. | 100.5 |
2.5 points
Question 19
Which statement(s) will instantiate a double array of 6 total elements?
| a. |
double [] [] cellbills = new double[2][]; cellbills[0] = new double[4]; cellbills[1] = new double[2]; | |
| b. |
double [] [] cellbills = { { 45.24, 54.67, 42.55, 44.61, 65.29 }, { 7 } }; | |
| c. |
Both a and b | |
| d. |
None of the above |
2.5 points
Question 20
Given an array int a [][] = new int[3][4] ,how do you access the element of array a located in the third row and the fourth column?
| a. |
a[3][4] | |
| b. |
a( 2,3 ) | |
| c. |
a{3}{4} | |
| d. |
a[2][3] |
2.5 points
Question 21
Which statement will return the number of rows in a two dimensional array a?
| a. |
int a = a.rows | |
| b. |
int a = a.length | |
| c. |
int a = a[i].length | |
| d. |
int a = a.size |
2.5 points
Question 22
What statement(s) could you use to declare and instantiate an ArrayList object reference of Book objects named library with a default capacity of 10 elements?
| a. |
ArrayList | |
| b. |
ArrayList library = new ArrayList | |
| c. |
both a and b | |
| d. |
neither a or b |
2.5 points
Question 23
What method of an arraylist class object returns the number of elements in an ArrayList object?
| a. |
size() | |
| b. |
capacity | |
| c. |
length | |
| d. |
length( ) |
2.5 points
Question 24
After the following code sequence is executed, what are the contents at ArrayList index 1 in a?
ArrayList
| a. | 10 | |
| b. | 7 | |
| c. | 4 | |
| d. | 21 |
2.5 points
Question 25
Which of the following is inherited by a subclass
| a. |
all instance variables and methods | |
| b. |
public instance variables and methods only | |
| c. |
protected instance variables and methods only | |
| d. |
protected and public instance variables and methods |
2.5 points
Question 26
Public Constructor methods
| a. |
Are inherited by but cannot be accessed by a subclass | |
| b. |
Are inherited by and can be accessed with the super keyword by a subclass | |
| c. |
Are accessible with the super keyword by a subclass but are not inherited | |
| d. |
Are not inherited by and cannot be accessed by a subclass |
2.5 points
Question 27
Assuming the class B extends class A, then
| a. |
An object of class B is an object of class A | |
| b. |
An object of class A is an object of class B | |
| c. |
Both a and b | |
| d. |
None of the above |
2.5 points
Question 28
What is the output of this code sequence?
Scanner parse = new Scanner("AA%:BB:CC"); parse.useDelimiter(":"); while(parse.hasNext()) {
System.out.print(parse.next() + " "); System.out.println();
}
| a. | AA% :BB :CC | |
| b. |
AA% BB CC | |
| c. | AA% BB CC | |
| d. |
None of the above |
2.5 points
Question 29
It is legal to have more than one catch block to match a try block but you must have a finally block if there is more than one catch block.
True
False
2.5 points
Question 30
Assuming file data.txt exists and is successfully opened and contains the following text
CS1
What does the file data.txt contain after this code sequence is executed?
try { FileOutputStream fos = new FileOutputStream("data.txt ", false ); PrintWriter pw = new PrintWriter( fos ); pw.println( Java Illuminated); pw.close( ); } catch( IOException ioe ) {
ioe.printStackTrace( );
}
| a. | Java Illuminated | |
| b. | CS1Java Illuminated | |
| c. | CS1 Java Illuminated | |
| d. | Java Illuminated CS1 |
2.5 points
Question 31
Given the following code for two service classes: public abstract class A { public A(){} public A(String x) { System.out.println(x + " Overloaded constructor for class A called "); } } public class B extends A { public B() { super("Hello"); } public B(String i) { super(i); } } And given the following code for the application class: public class App { public static void main(String[] args) { B b = new B(); System.out.println("Hello Again "); } } What would the output be when the application class is executed? | a. |
Nothing is output | |
| b. |
Hello Overloaded constructor for class A called Hello Again | |
| c. |
Hello Again | |
| d. |
Overloaded constructor for class A called Hello Again |
2.5 points
Question 32
Java, multiple inheritance is implemented with the keyword implements using the concept of
| a. |
An abstract class | |
| b. |
One direct superclass only | |
| c. |
An interface | |
| d. |
Multiple inheritance is not supported in Java |
2.5 points
Question 33
A non abstract subclass extending an abstract superclass must provide the implementation for all direct abstract superclass abstract methods.
True
False
2.5 points
Question 34
For Question 34 consider the following three classes: public class A { private int number; protected String name; public double price; public A() { System.out.println( "A() called"); } private void foo1() { System.out.println( "A version of foo1() called"); } protected int foo2() { System.out.println( "A version of foo2() called"); return number; } public String foo3() { System.out.println( "A version of foo3() called"); return "Hi"; } } public class B extends A { private char service; public B() { super(); System.out.println( "B() called" ); } public void foo1() { System.out.println( "B version of foo1() called"); } protected int foo2() { int n = super.foo2(); System.out.println( "B version of foo2() called"); return ( n + 5 ); } public String foo3() { String temp = super.foo3(); System.out.println( "B version of foo3() called"); return ( temp + " foo3"); } } public class C extends B { public C() { super(); System.out.println( "C() called"); } public void foo1() { System.out.println( "C version of foo1() called"); } } What is the output of the following code sequence: B b2 = new B(); b2.foo1(); | a. | A() called B() called A version of foo1() called | |
| b. | A() called B() called A version of foo1() called B version of foo1() called | |
| c. | A() called B() called B version of foo1() called | |
| d. | A() called B() called B version of foo1() called A version of foo1() called |
2.5 points
Question 35
For Question 35 consider the following three classes: public class A { private int number; protected String name; public double price; public A() { System.out.println( "A() called"); } private void foo1() { System.out.println( "A version of foo1() called"); } protected int foo2() { System.out.println( "A version of foo2() called"); return number; } public String foo3() { System.out.println( "A version of foo3() called"); return "Hi"; } } public class B extends A { private char service; public B() { super(); System.out.println( "B() called" ); } public void foo1() { System.out.println( "B version of foo1() called"); } protected int foo2() { int n = super.foo2(); System.out.println( "B version of foo2() called"); return ( n + 5 ); } public String foo3() { String temp = super.foo3(); System.out.println( "B version of foo3() called"); return ( temp + " foo3"); } } public class C extends B { public C() { super(); System.out.println( "C() called"); } public void foo1() { System.out.println( "C version of foo1() called"); } }
What is the output of the following code sequence: B b3 = new B(); int n = b3.foo2();
| a. | A() called B() called A version of foo2() called B version of foo2() called | |
| b. |
A() called B() called A version of foo2() called B version of foo2() called 5 | |
| c. | A() called B() called B version of foo2() called 5 | |
| d. | B() called A() called B version of foo2() called |
2.5 points
Question 36
For Question 36 consider the following three classes: public class A { private int number; protected String name; public double price; public A() { System.out.println( "A() called"); } private void foo1() { System.out.println( "A version of foo1() called"); } protected int foo2() { System.out.println( "A version of foo2() called"); return number; } public String foo3() { System.out.println( "A version of foo3() called"); return "Hi"; } } public class B extends A { private char service; public B() { super(); System.out.println( "B() called" ); } public void foo1() { System.out.println( "B version of foo1() called"); } protected int foo2() { int n = super.foo2(); System.out.println( "B version of foo2() called"); return ( n + 5 ); } public String foo3() { String temp = super.foo3(); System.out.println( "B version of foo3() called"); return ( temp + " foo3"); } } public class C extends B { public C() { super(); System.out.println( "C() called"); } public void foo1() { System.out.println( "C version of foo1() called"); } }
What is the output of the following code sequence: B b4 = new B(); System.out.println( b4.foo3() );
| a. | A() called B() called A version of foo2() called Hi B version of foo2() called | |
| b. | A() called B() called A version of foo3() called B version of foo3() called Hi foo3 | |
| c. | A() called B() called A version of foo3() called B version of foo3() called | |
| d. | A() called B() called Hi foo3 |
2.5 points
Question 37
True or False, a method from a subclass that overrides a superclass method having the same method signature cannot call that superclass method from within the overriding subclass method body.
True
False
2.5 points
Question 38
For Question 38 consider the following two classes: public abstract class C { private void foo1() { System.out.println( Hello foo1 ); } public abstract void foo2(); public abstract int foo3(); public void foo1Call() { foo1(); } } public class D extends C { public void foo2() { System.out.println( Hello foo2 ); } public int foo3() { return 10; } private void foo4() { System.out.println( Hello D foo4() ); } }
To instantiate an object of class C we could use the following statement(s):
| a. | C c2; c2 = new C(); | |
| b. |
C c2 = new C(); | |
| c. |
a or b | |
| d. |
none of the above |
2.5 points
Question 39
For Question 39 consider the following two classes: public abstract class C { private void foo1() { System.out.println( Hello foo1 ); } public abstract void foo2(); public abstract int foo3(); public void foo1Call() { foo1(); } } public class D extends C { public void foo2() { System.out.println( Hello foo2 ); } public int foo3() { return 10; } private void foo4() { System.out.println( Hello D foo4() ); } }
Which of the following code sequences, if any, will successfully access private method foo1 in class C?
| a. | C c2 = new C(); c2.foo1(); | |
| b. | C c2 ; c2 = new D(); c2.foo1(); | |
| c. | D d1 = new D(); d1.foo1(); | |
| d. | C c1 = new D(); c1.foo1Call(); | |
| e. | None of the above |
2.5 points
Question 40
Assuming a StringIndexOutOfBoundsException exception class exists and is a subclass of IndexOutofBoundsException, what is the output of this code sequence? try { String word = new String("avaJ"); System.out.println( word.charAt( 3 ) ); } catch( StringIndexOutOfBoundsException e ) { System.out.println( OOPS! ); } catch( IndexOutOfBoundsException ie ) { System.out.println( ie.getMessage() ); } finally() { System.out.println("Id rather be sailing "); }
| a. | OOPS! A message indicating the cause of the exception thrown Id rather be sailing | |
| b. | J Id rather be sailing | |
| c. | OOPS! Id rather be sailing | |
| d. |
J |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
