Menu

[solved]-1 Valid Box Object Instantiation Public Class Box Private E Data Public Box Box Box New Q39011310

1. Which is a valid Box object instantiation?

public class Box

{  

   private E data;

   public Box(){ . . . }

}

Box box = new Box();

Box box = new Box;

Box box = new Box();

Box box = new Box();

2. The type of the exception object thrown is always the same asthe type declared in the catch clause that catches it.

TrueFalse

3.

The output of the following code is _________.

public class Test

{

    static int count = 0;

    public static void main(String[] args)

   {

      f(7);

      System.out.println(count);

    }

    public static int f(int n)

   {

      count++;

      if (n == 0) return 1;

      else return f(n – 1) + n * n;

    }

}

8

9

6

7

4. What does the following recursive method do?

    public static String x(String str)
   {
        if (str.length() < 1)return “”;
       String firstChar =str.substring(0,1);
       if (firstChar.equals(“x”))
       {
           returnx(str.substring(1));
       }
       else
       {
           return firstChar+ x(str.substring(1));
       }
   }

5. Which statement is true about the following constructor ofthe BankAccountclass?

public BankAccount(double balance)

{

   this.balance = balance;

}

The code has a syntax error.

The code has a logic error.

The code sets the instance variable balance to the parametervariable balance.

You can’t have an instance variable and a parameter variablewith the same name.

Expert Answer


Answer to 1. Which is a valid Box object instantiation? public class Box { private E data; public Box(){ . . . } } Box box = new B… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *