SmartTutor

(19)

$20/per page/Negotiable

About SmartTutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Business & Finance See all
Accounting,Business & Finance,Economics,English,HR Management,Math Hide all
Teaching Since: Apr 2017
Last Sign in: 1 Day Ago
Questions Answered: 4186
Tutorials Posted: 4117

Education

  • BS,MBA, PHD
    Adelphi University/Devry
    Apr-2000 - Mar-2005

Experience

  • HOD ,Professor
    Adelphi University
    Sep-2007 - Apr-2017

Category > Computer Science Posted 12 Aug 2019 My Price 9.00

Assuming a StringIndexOutOfBoundsException exception class exists, what is the output of this code sequence?

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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      Given the following code declaring and initializing three boolean variables x, y and z with respective values falsefalse, 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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      Which of the following is not a valid wrapper class?

a.

Integer

b.

Double

c.

Char

d.

Boolean

2.5 points   

QUESTION 17

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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<Book >  library  =  new ArrayList<Book>();

b.

ArrayList<Book >  library;

library = new ArrayList<Book>();

c.

both a and b

d.

neither a or b

2.5 points   

QUESTION 23

1.      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

1.      After the following code sequence is executed, what are the contents at ArrayList index 1 in a?

ArrayList<Integer>  a = new ArrayList<Integer>( );
a.add( 7 );
a.add( 10 );
a.add( 21 );
a.set( 1, 4 );
a.remove( 0 );

a.

10

b.

7

c.

4

d.

21

2.5 points   

QUESTION 25

1.      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

1.      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

1.      Assuming the class 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

1.      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

1.      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

1.      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

1.      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\n");
     }
}
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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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

1.      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!\n” );
}

     catch( IndexOutOfBoundsException ie )
{
     System.out.println( ie.getMessage() );
}

finally()
{
     System.out.println("I’d rather be sailing\n");
}

a.

OOPS!
A message indicating the cause of the exception thrown
I’d rather be sailing

b.

J
I’d rather be sailing

c.

OOPS!

I’d rather be sailing

d.

J

2.5 points   

Click Save and Submit to save and submit. Click Save All Answers to save all answers.

 

Answers

(19)
Status NEW Posted 12 Aug 2019 05:08 AM My Price 9.00

-----------

Attachments

file 1565590042-Javajava.docx preview (112 words )
P-----------lea-----------se -----------fin-----------d a-----------nsw-----------ers----------- be-----------low----------- :A-----------nsw-----------er -----------1 :----------- d.----------- A-----------nsw-----------er -----------2: -----------C -----------Ans-----------wer----------- 3 -----------: b----------- A-----------nsw-----------er -----------4 :----------- c ----------- An-----------swe-----------r 5----------- : -----------d -----------Ans-----------wer----------- 6:----------- d ----------- An-----------swe-----------r 7-----------: b----------- A-----------nsw-----------er -----------8 :----------- d ----------- An-----------swe-----------r 9-----------: T-----------rue----------- A-----------nsw-----------er -----------10 -----------: a----------- A-----------nsw-----------er -----------11:----------- d ----------- An-----------swe-----------r 1-----------2: -----------d -----------Ans-----------wer----------- 13----------- : -----------Tru-----------e -----------Ans-----------wer----------- 14----------- : -----------Fal-----------se ----------- An-----------swe-----------r 1-----------5 :----------- d ----------- An-----------swe-----------r 1-----------6: -----------c -----------Ans-----------wer----------- 17----------- : -----------a -----------Ans-----------wer----------- 18----------- : -----------c -----------Ans-----------wer----------- 19----------- : -----------c -----------Ans-----------wer----------- 20----------- : -----------d -----------Ans-----------wer----------- 21----------- : -----------b -----------Ans-----------wer----------- 22----------- : -----------c -----------Ans-----------wer----------- 23----------- :a-----------Ans-----------wer----------- 24----------- : -----------d -----------Ans-----------wer----------- 25----------- : -----------d -----------Ans-----------wer----------- 26----------- : -----------c -----------Ans-----------wer----------- 27----------- : -----------d -----------Ans-----------wer----------- 28-----------
Not Rated(0)