Java Exam1

10 Questions | Total Attempts: 47

SettingsSettingsSettings
Please wait...
Java Exam1

Java Multiple type Question


Questions and Answers
  • 1. 
    Consider the following code: public class TestOne {    public static void main(String args[])      {        byte x = 3;         byte y = 5;         System.out.print((y%x) + ", "); System.out.println(y == ((y/x) *x +(y%x))); } } Which of the following gives the valid output for above?
    • A. 

      Prints 2, false

    • B. 

      Prints: 1, true

    • C. 

      Prints: 2, true

    • D. 

      Prints: 1, true

  • 2. 
    Consider the following program:   class A extends Thread {    public A(Runnable r) {}    public void run() {    System.out.print("A");    } }  class B implements Runnable {    public void run(){    System.out.print("B");    } }  class C{    public static void main(String[] args) {    new A(new B()).start();    } }  What will be the output of the above program?
    • A. 

      Compile-time error

    • B. 

      Prints: AB

    • C. 

      Prints: BA

    • D. 

      Prints: A

    • E. 

      Prints: B

  • 3. 
    Dd3)6)  Consider the following code:   public class Code17  {      public static void main(String args[]) {      new Code17();       }      { System.out.print("Planet "); }      { System.out.print("Welcome "); }      }      Which of the following will be the valid output for the above code?
    • A. 

      Compilation Error

    • B. 

      Planet

    • C. 

      Planet Welcome

    • D. 

      Welcome Planet

  • 4. 
    10.2 Q2: Polymorphism allows for specifics to be dealt with during:
    • A. 

      A. execution.

    • B. 

      B. compilation.

    • C. 

      C. programming.

    • D. 

      D. debugging.

  • 5. 
    9.5 Q1: When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable?
    • A. 

      A. A syntax error occurs.

    • B. 

      B. A compile-time error occurs.

    • C. 

      C. A run-time error occurs.

    • D. 

      D. The program compiles and runs because the instance variables are initialized to their default values.

  • 6. 
    10.5 Q1: It is a UML convention to denote the name of an abstract class in:
    • A. 

      A. bold.

    • B. 

      B. italics.

    • C. 

      C. a diamond.

    • D. 

      D. there is no convention of the UML to denote abstract classes—they are listed just as any other class.

  • 7. 
    Given:Which is most likely true? (Choose the most likely.)
    • A. 

      ClassD has low cohesion

    • B. 

      ClassA has weak encapsulation

    • C. 

      ClassB has weak encapsulation

    • D. 

      ClassB has strong encapsulation

    • E. 

      ClassC is tightly coupled to ClassA

  • 8. 
    Consider the abstract superclass below:public abstract class Foo{   private int a;   public int b;   public Foo( int aVal, int bVal )   {      a = aVal;      b = bVal;   } // end Foo constructor   public abstract int calculate();} // end class FooAny concrete subclass that extends class Foo:
    • A. 

      A. Must implement a method called calculate.

    • B. 

      B. Will not be able to access the instance variable a.

    • C. 

      C. Neither (a) nor (b).

    • D. 

      D. Both (a) and (b)

  • 9. 
    Given:Which is most likely true? (Choose the most likely.)
    • A. 

      ClassD has low cohesion

    • B. 

      ClassA has weak encapsulation

    • C. 

      ClassB has weak encapsulation

    • D. 

      ClassB has strong encapsulation

    • E. 

      ClassC is tightly coupled to ClassA

  • 10. 
    10.5.6 Q2: Every object in Java knows its own class and can access this information through method         .
    • A. 

      A. getClass.

    • B. 

      B. getInformation.

    • C. 

      C. objectClass.

    • D. 

      D. objectInformation.