GoConqr has a new look! Let us know what you think.

Quiz

01-Wrong-Questions-OCA-JAVA-SE

Wong Fei Hung 13 questions Updated 2 Aug 2017

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (13)

  1. 1Following is a supposedly robust method to parse an input for a float :
    public float parseFloat( String s) {
    float f = 0. 0f;
    try{
    f = Float. valueOf( s) . floatValue( ) ;
    return f ;
    }c
    atch( NumberFormatException nfe) {
    System. out. println( " Invalid input " + s) ;
    f = Float. NaN ;
    return f;
    }f
    inally { System. out. println( " finally" ) ; }
    return f ;
    }Whi
    ch ofthe following statements about the above method are true??
    1. AIfinput is " 0. 1" then it will return 0. 1 and print finally.
    2. BIfinput is " 0x. 1" then it will return Float. Nan and print Invalid Input 0x. 1
      and finally.
    3. CIfinput is " 1" then it will return 1. 0 and print finally.
    4. DIfinput is " 0x1" then it will return 0. 0 and print Invalid Input 0x1 and
      finally.
    5. EThe code will not compile.
  2. 210. QID - 2.1178 : Working with Methods
    Which one ofthe following class definitions is/are a legal definition ofa class that
    cannot be instantiated?
    class Automobile{
    abstract void honk( ) ; //( 1)
    }a
    bstract class Automobile{
    void honk( ) ; //( 2)
    }a
    bstract class Automobile{
    void honk( ) { } ; //( 3)
    }a
    bstract class Automobile{
    abstract void honk( ) { } //( 4)
    }a
    bstract class Automobile{
    abstract void honk( ) ; //( 5)
    }
    1. A1
    2. B2
    3. C3
    4. D4
    5. E5
  3. 3Which ofthe following statements are true?
    1. ASystem. out. println( 1 + 2 + " 3" ) ; would print 33.
    2. BSystem. out. println( " 1" + 2 + 3) ; would print 15.
    3. CSystem. out. println( 4 + 1. 0f) ; would print 5.0
    4. DSystem. out. println( 5/4) ; would print 1.25
    5. ESystem. out. println( ' a' + 1 ) ; would print b.
  4. 4Which ofthe following statements are true?
    1. Aprivate keyword can never be applied to a class.
    2. Bsynchronized keyword can never be applied to a class.
    3. Csynchronized keyword may be applied to a non-primitive variable.
    4. Dfinal keyword can never be applied to a class.
    5. EA final variable can be shadowed in a subclass.
  5. 5Which ofthese statements are true?
    1. AA static method can call other non-static methods in the same class by using the
      'this' keyword.
    2. BA class may contain both static and non-static variables and both static and nonstatic methods.
    3. CEach object ofa class has its own copy ofeach non-static member variable.
    4. DInstance methods may access local variables ofstatic methods.
    5. EAll methods in a class are implicitly passed a 'this' parameter when called.
  6. 6Consider the following class:
    public class PortConnector{
    public PortConnector( int port) throws IOException{
    . . . lot of valid code.
    }.
    . . other valid code.
    }Y
    ou want to write another class CleanConnector that extends from PortConnector.
    Which ofthe following statements should hold true for CleanConnector class?
    1. AIt is not possible to define CleanConnector that does not throw IOException at
      instantiation.
    2. BPortConnector class itselfis not valid because you cannot throw any exception
      from a constructor.
    3. CCleanConnector's constructor cannot throw any exception other than
      IOException.
    4. DCleanConnector's constructor cannot throw any exception other than subclass of
      IOException.
    5. ECleanConnector's constructor cannot throw any exception other than superclass of
      IOException.
    6. FNone ofthese.
  7. 7Consider the following classes :
    class A{
    public void mA( ) { } ;
    }c
    lass B extends A {
    public void mA( ) { }
    public void mB( ) { }
    }c
    lass C extends B {
    public void mC( ) { }
    }a
    nd the following declarations:
    A x = new B( ) ; B y = new B( ) ; B z = new C( ) ;
    Which ofthe following calls are polymorphic calls?
    1. Ax. mA( ) ;
    2. Bx. mB( ) ;
    3. Cy. mA( ) ;
    4. Dz. mC( ) ;
    5. Ez. mB( ) ;
  8. 8What will be the result ofattempting to compile and run the following program?
    public class TestClass{
    public static void main( String args[ ] ) {
    Exception e = null;
    throw e;
    }
    }
    1. AThe code will fail to compile.
    2. BThe program will fail to compile, since it cannot throw a null.
    3. CThe program will compile without error and will throw an Exception when run.
    4. DThe program will compile without error and will throw
    5. EThe program will compile without error and will run and terminate without any
      output.
  9. 9Consider the following code:
    interface Flyer{ }
    class Bird implements Flyer { }
    class Eagle extends Bird { }
    class Bat { }
    public class TestClass {
    public static void main( String[ ] args) {
    Flyer f = new Eagle( ) ;
    Eagle e = new Eagle( ) ;
    Bat b = new Bat( ) ;
    if( f instanceof Bird) System. out. println( " f is a Bird" ) ;
    if( e instanceof Flyer) System. out. println( " e is a Flyer" ) ;
    if( b instanceof Flyer) System. out. println( " f is a Bird" ) ;
    }
    }Wha
    t will be printed when the above code is compiled and run?
    1. AIt will not compile.
    2. BIt will throw an exception when run.
    3. Cfis a Bird
      e is a Flyer
    4. DD. fis a Bird
    5. Ee is a Flyer
  10. 10What will be the result ofattempting to compile and run the following program?
    class TestClass{
    public static void main( String args[ ] ) {
    int i = 0;
    for ( i=1 ; i<5 ; i++) continue; //( 1)
    for ( i=0 ; ; i++) break; //( 2)
    for ( ; i<5?false: true ; ) ; //( 3)
    }
    }
    1. AThe code will compile without error and will terminate without problems when
      run
    2. BThe code will fail to compile, since the continue can't be used this way.
    3. CThe code will fail to compile, since the break can't be used this way
    4. DThe code will fail to compile, since the for statement in the line 2 is invalid.
    5. EThe code will compile without error but will never terminate.

Information

Description
Wrong-Question-OCA-SE-I Quiz on 01-Wrong-Questions-OCA-JAVA-SE, created by Wong Fei Hung on 02/08/2017.
Language
Português
Views
1
History
Created on 2 Aug 2017 · updated on 2 Aug 2017
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?