¡GoConqr estrena diseño! Cuéntanos qué te parece.

Test

02

Wong Fei Hung 80 preguntas

Hacer el test

Preguntas del test (80)

  1. 1Which line, ifany, will give a compile time error ?

    void test( byte x) {
    switch( x) {
    case ' a' : // 1
    case 256: // 2
    case 0: // 3
    default : // 4
    case 80: // 5
    }
    }
    1. ALine 1 as 'a' is not compatible with byte
    2. BLine 2 as 256 cannot fit into a byte.
    3. CNo compile time error but a run time error at line 2.
    4. DLine 4 as the default label must be the last label in the switch statement.
    5. EThere is nothing wrong with the code.
  2. 2What is wrong with the following code?
    class MyException extends Exception { }
    public class TestClass{
    public static void main( String[ ] args) {
    TestClass tc = new TestClass( ) ;
    try{
    tc. m1( ) ;
    }c
    atch ( MyException e) {
    tc. m1( ) ;
    }f
    inally{
    tc. m2( ) ;
    }
    }p
    ublic void m1( ) throws MyException{
    throw new MyException( ) ;
    }p
    ublic void m2( ) throws RuntimeException{
    throw new NullPointerException( ) ;
    }
    }
    1. AIt will not compile because you cannot throw an exception in finally block
    2. BIt will not compile because you cannot throw an exception in catch block.
    3. CIt will not compile because NullPointerException cannot be created this way
    4. DIt will not compile because ofunhandled exception
    5. EIt will compile but will throw an exception when run
  3. 3What will be the result ofattempting to compile and run the following code?
    class TestClass{
    public static void main( String args[ ] ) {
    String str1 = " str1" ;
    String str2 = " str2" ;
    System. out. println( str1. concat( str2) ) ;
    System. out. println( str1) ;
    }
    }
    1. AThe code will fail to compile.
    2. BThe program will print str1 and str1.
    3. CThe program will print str1 and str1str2
    4. DThe program will print str1str2 and str1
    5. EThe program will print str1str2 and str1str2.
  4. 4What is the result ofexecuting the following fragment ofcode:
    boolean b1 = false;
    boolean b2 = false;
    if ( b2 ! = b1 = ! b2) {
    System. out. println( " true" ) ;
    }e
    lse{
    System. out. println( " false" ) ;
    }
    1. ACompile time error
    2. BIt will print true.
    3. CIt will print false
    4. DRuntime error
    5. EIt will print nothing
  5. 5Which ofthe following are benefits ofArrayList over an array?
    1. AYou do not have to worry about the size ofthe ArrayList while inserting elements.
    2. BIt consumes less memory space.
    3. CYou do not have to worry about thread safety.
    4. DIt allows you to write type safe code.
  6. 6Given the following code:
    class M { }
    class N{
    private M m = new M( ) ;
    public void makeItNull( M pM) {
    pM = null;
    }p
    ublic void makeThisNull( ) {
    makeItNull( m) ;
    }p
    ublic static void main( String[ ] args) {
    N n = new N( ) ;
    n. makeThisNull( ) ;
    }
    }Whi
    ch ofthe following statements are correct?
    1. AThere are no instances ofM to be garbage collected till the program ends.
    2. BA call to n. makeThisNull( ) marks the private instance ofM for garbage
      collection.
    3. CSetting pM = null; in makeItNull( ) , marks the private instance ofM for garbage
      collection.
    4. Dprivate members ofa class become eligible for garbage collection only when the
      instance ofthe class itselfbecomes eligible for garbage collection.
  7. 7package p;
    private class TC extends j ava. util. HashMap{
    public TC( ) {
    super( 100) ;
    System. out. println( " TC created" ) ;
    }
    }p
    ublic class TestClass extends TC{
    public TestClass( ) {
    System. out. println( " TestClass created" ) ;
    }p
    ublic static void main( String[ ] args) { new TestClass( ) ; }
    }Wha
    t will be the output when TestClass is run?
    1. A" TestClass created" as well as " TC created".
    2. BIt will not compile because HashMap is a final class.
    3. COnly " TestClass created" will be printed.
    4. DOnly " TC created" will be printed.
    5. ENone ofthe above are correct.
  8. 8class TestClass{
    public static void main( String args[ ] ) {
    int k = 0;
    int m = 0;
    for ( int i = 0; i <= 3; i++) {
    k++;
    if ( i == 2) {
    // line 1
    }m
    ++;
    }S
    ystem. out. println( k + " , " + m ) ;
    }
    }
    1. AIt will print 3, 2 when line 1 is replaced by break;
    2. BIt will print 3, 2 when line 1 is replaced by continue.
    3. CIt will print 4, 3 when line 1 is replaced by continue.
    4. DIt will print 4, 4 when line 1 is replaced by i = m++;
    5. EIt will print 3, 3 when line 1 is replaced by i = 4;
  9. 9What can be the type ofa catch argument ?
    1. AAny class that extends j ava. lang. Exception
    2. BAny class that extends j ava. lang. Exception except any class that extends
      j ava. lang. RuntimeException
    3. CAny class that is-a Throwable.
    4. DAny Object
    5. EAny class that extends Error
  10. 10public class Varargs{
    public void test( ) {
    test1( 10) ; //1
    test1( 10, 20) ; //2
    }p
    ublic static void main( String[ ] args) {
    new Varargs( ) . test( ) ;
    }/
    /insert method here.
    }Whi
    ch ofthe following lines can be added independently to the above class so that it
    will run without any errors or exceptions?
    1. Apublic void test1( int i, int j ) { }
    2. Bpublic void test1( int i, int. . . j ) { }
    3. Cpublic void test1( int. . . i) { }
    4. Dpublic void test1( int i. . . ) { }
    5. Epublic void test1( int[ ] i) { }

Información

Descripción
Exam Mock EthuWare -OCA-SE-7-I Test sobre 02, creado por Wong Fei Hung el 30/07/2017.
Idioma
Português
Visitas
0
Valoración
Aún sin valoraciones
Valora este test
Valora este test

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?