Description of this paper

Loading

QUESTION 1 The main purpose of a constructor is: A. Construct a-(Answered)

Description

Step-by-step Instant Solution


Question

QUESTION 1

  1. The main purpose of a constructor is:

    A.

    Construct a method

    B.

    Initialize instance variables

    C.

    Return a value

    D.

    Name the method

4 points ??

QUESTION 2
  1. Assume the following class definition:

    ?public class MyClass
    {
    ????public void myMethod()
    ????{
    ????????...
    ????}
    }

    ?You define the following subclass:

    ?public class OurClass extends MyClass
    {
    ????public void ourMethod()
    ????{
    ????????myMethod();
    ????????...
    ????}
    }

    ?What happens when you try to compile?OurClass?

    A.

    It will compile

    B.

    It will compile but an object of?OurClass?cannot be created

    C.

    It will not compile

    D.

    It will compile but an object of?MyClass?cannot be created

4 points ??

QUESTION 3
  1. How many times will "hello" be printed by the following:


    for (int i = 0; i < 10; i++)

    ????System.out.println("hello");

    A.
    0
    B.
    10
    C.
    9
    D.
    11

4 points ??

QUESTION 4
  1. Which one of the following is a valid constructor method header for a class named?Car?

    A.

    public class Car(String model)

    B.

    Public Class Car

    C.

    public car(String model)

    D.

    public Car(String model)

4 points ??

QUESTION 5
  1. A subclass can directly access all public and private instance variables of its superclass?

    ?True

    ?False

4 points ??

QUESTION 6
  1. Given this code fragment:?

    {
    ??? int x = 5, y = 6, z = 7;?

    ??? foo(x, y, z);
    ??? System.out.println(x + ", " + y + ", " + z);
    }

    public void foo(int a, int b, int c)
    {
    ??? a = a + 3;
    ??? b = a + c;
    ??? c = c + b
    }

    What is the output?

    A.

    5, 6, 7

    B.

    2, 0, 4

    C.

    8, 15, 22

    D.

    8, 12, 13

4 points ??

QUESTION 7
  1. A checked exception
    A.
    Cannot be analyzed by the compiler
    B.
    Must either be caught or declared within the method where it may be thrown
    C.
    Is any subclass of RuntimeException
    D.
    Can be ignored and left to Java to handle

4 points ??

QUESTION 8
  1. Given this code segment:

    ?

    try

    {

    ????...

    }

    catch (IOException e)

    {

    ????System.out.println("I/O exception");

    }

    catch (NumberFormatException e)

    {

    ????System.out.println("Number format exception");

    }

    System.out.println("Done");

    ?

    What will be printed if no error occurs in the?try?block?

    A.

    "I/O exception"?and then?"Done"

    B. "I/O exception"?only
    C.

    "Done"?only

    D.

    nothing will print

    E.

    "Number format exception"?and then?"Done"

    F.

    "I/O exception"?then?"Number format exception"?and then?"Done"

4 points ??

QUESTION 9
  1. Multiplying an?int?(such as?5) by a?double?(such as?0.1) gives

    A.

    an?int

    B.

    a?double

    C.

    an error

    D.

    an exception is thrown

4 points ??

QUESTION 10
  1. You create an object of a class using the keyword ____ .

    A.

    abstract

    B.

    new

    C.

    extends

    D.

    create

4 points ??

QUESTION 11
  1. Given the following class definition:

    ?

    public class Car

    {

    ?????private double fuelLevel;

    ?

    ?????public Car(double gallons)

    ?????{

    ??????????fuelLevel = gallons;

    ?????}

    ?

    ?????public void addGas(double gallons)

    ?????{

    ??????????fuelLevel += gallons;

    ?????}

    }

    ?

    and this code segment:

    ?

    Car car1 = new Car(20);

    Car car2 = car1;

    car2.addGas(10);

    ?

    What is the value stored in?fuelLevel?for?car1?

    A.

    0.0

    B.

    20.0

    C.

    10.0

    D.

    30.0

4 points ??

QUESTION 12
  1. After executing this code segment:

    ?

    double v1 = 2000.0;

    double v2 = v1;

    v2 = v2 + 500.0;

    ?

    What will be the value of?v1?

    A.

    2000.0

    B.

    0.0

    C.

    2500.0

    D.

    Unknown

4 points ??

QUESTION 13
  1. When writing a subclass, which of the following are true?

    A.

    You can override/redefine methods of the superclass

    B.

    You can inherit methods from the superclass

    C.

    You can define new methods in the subclass

    D.

    All of the above

4 points ??

QUESTION 14
  1. Given?

    int quantity = 3;

    double value = 7.52;

    String number = "one";?

    Which?of all of the following?are valid assignments?

    A.

    quantity = value;

    B.

    quantity = (int)value;

    C.

    value = quantity;

    D.

    quantity = (double)value;

    E.

    quantity = number;

    F.

    Both B and C

4 points ??

QUESTION 15
  1. Given these two class definitions:

    ?

    public class Adder

    {

    ????private double balance = 0.0;

    ???

    ????public void addIt(double amount)

    ????{

    ???????balance = balance + amount;

    ????}

    ????public double getBalance()

    ????{

    ???????return balance;

    ????}

    }

    ?

    And:

    ?

    public class NewAdder extends Adder

    {

    ????private int count = 0;

    ?

    ????public void addIt(double amount)

    ????{

    ????????super.addIt(amount / 2.0);

    ????????count = count + 1;

    ????}

    }

    ?

    Now consider code segment:

    ?

    NewAdder myAdd = new NewAdder();

    myAdd.addIt(500.0);

    System.out.println(myAdd.getBalance());

    ?

    What will be printed:

    A.

    250.0

    B.

    does not compile

    C.

    500.0

    D.

    0.0

4 points ??

QUESTION 16
  1. Select the best answer.

    ?

    A(n) ____ can add instance variables and methods to an existing class.

    A.

    subclass

    B.

    constructor

    C.

    package

    D.

    interface

4 points ??

QUESTION 17
  1. The Java keyword that ensures that a block of code will always be executed whether or not an exception is thrown is:

    A.

    always

    B.

    execute

    C.

    finally

    D.

    do

4 points ??

QUESTION 18
  1. If a subclass constructor does not explicitly call a superclass constructor, the superclass default (no argument) constructor is always called automatically.

    ?True

    ?False

4 points ??

QUESTION 19
  1. Which of the following are Java naming conventions?

    ?

    #1:???????Classes start with an uppercase letter

    #2:???????Methods start with an uppercase letter

    #3:???????Object start with a lowercase letter

    #4:???????Objects start with an uppercase letter

    #5:???????Classes start with a lowercase letter

    #6:???????Methods start with a lowercase letter

    A.

    #1, #2 and #4

    B.

    #1, #3 and #6

    C.

    #3, #5 and #6

    D.

    #4, #5 and #6

4 points ??

QUESTION 20
  1. Suppose the class?Sub?inherits from the superclass?Sandwich.? Which of the following gives a syntax error??

    Sandwich x = new Sandwich();
    Sub y = new Sub();

    A.

    x = y;

    B.

    y = new Sub();

    C.

    y = x;

    D.

    x = new Sub();

4 points ??

QUESTION 21
  1. Select the best answer.

    ?

    Local variables are destroyed when

    A.

    the constructor runs

    B.

    the method ends

    C.

    you explicitly delete them

    D.

    the object is no longer in use

4 points ??

QUESTION 22
  1. The compiler will generate an error if the same name but different signature is used for more than one method or constructor.

    ?True

    ?False

4 points ??

QUESTION 23
  1. A(n) __________________ exception describes a problem that is likely to occur at times, no matter how careful you are.

    A.

    RuntimeException

    B.

    Error

    C.

    unchecked

    D.

    checked

4 points ??

QUESTION 24
  1. Given the array

    ?

    double cost[] = new double[5];

    ?

    How would you access the last element of the array?

    A.

    cost.get[5]

    B.

    cost.get(4)

    C.

    cost[5]

    D.

    cost[4]

4 points ??

QUESTION 25
  1. Which of the following will make?Student?a subclass of the?Person?class?

    A.

    public class Student implements Person

    B.

    public class Person extends Student

    C.

    public class Person implements Student

    D.

    public class Student subclasses Person

    E.

    public class Student extends Person



1) B

 

2) A

 

3) B

 

4) D

 

5) FALSE

 

6) A

 

7) A

 

8) C

 

9) B

 

10) B

 

11) B

 

12) A

 

13) D

 

14) B

 

15) A

 

16) D

 

17) C

 

18) TRUE

 

19) D

 

20) D

 

21) B

 

22) FALSE

 

23) D

 

24) D

 

25) E

 

Paper#9256531 | Written in 27-Jul-2016

Price : $16
SiteLock