Skip to main content

--> Test your Knowledge

 

Multiple Choice Questions

  1. Which is true? (Choose all that apply)
    1. "X extends Y" is correct if and only is X is a class and Y is an interface.
    2. "X extends Y" is correct if and only is X is an interface and Y is a class.
    3. "X extends Y" is correct if X and Y are either both classes or both interfaces.
    4. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
  2. Given:
  3. class Voop {
        public static void main(String[] args) {
            doStuff(1);
            doStuff(1, 2);
        }
        // Insert your code here
    }

    Which statement can be inserted (Choose all that apply)?

    1. static void doStuff(int... doArgs) {}
    2. static void doStuff(int[] doArgs) {}
    3. static void doStuff(int doArgs...) {}
    4. static void doStuff(int doArgs..., int y) {}
    5. static void doStuff(int x, int... doArgs) {}
  4. Given:
  5. enum Animals {
        DOG("woof"), CAT("meow"), FISH("burble");
        String sound;
        Animals(String s) {
            sound = s;
        }
    }
    class TestEnum {
        static Animals a;
        public static void main(String[] args) {
            System.out.println(a.DOG.sound + " " + a.FISH.sound);
        }
    }

    What is the result?

    1. woof burble
    2. Multiple compilation errors
    3. Compilation fails due to an error on line 2
    4. Compilation fails due to an error on line 3
    5. Compilation fails due to an error on line 4
    6. Compilation fails due to an error on line 11
  6. Given two files:
  7. package pkgA;
    public class Foo {
        int a = 5;
        protected int b = 6;
        public int c = 7;
    }
    package pkgB;
    import pkgA.*;
    public class Baz {
        public static void main(String[] args) {
            Foo f = new Foo();
            System.out.print(" " + f.a);
            System.out.print(" " + f.b);
            System.out.print(" " + f.c);
        }
    }

    What is the result? (Choose all that apply)

    1. 5 6 7
    2. 5 followed by an exception
    3. Compilation fails due to an error on line 11
    4. Compilation fails due to an error on line 12
    5. Compilation fails due to an error on line 13
    6. Compilation fails due to an error on line 14
  8. Given
  9. public class Electronic implements Device {
        public void doIt() {
        }
    }
    abstract class Phone1 extends Electronic {
    }
    abstract class Phone2 extends Electronic {
        public void doIt(int x) {
        }
    }
    class Phone3 extends Electronic implements Device {
        public void doStuff() {
        }
    }
    interface Device {
        public void doIt();
    }

    What is the result? (Choose all that apply)

    1. Compilation succeeds
    2. Compilation fails due to an error on line 1
    3. Compilation fails due to an error on line 5
    4. Compilation fails due to an error on line 7
    5. Compilation fails due to an error on line 11
    6. Compilation fails due to an error on line 15
  10. Given
  11. class Announce {
        public static void main(String[] args) {
            for(int __x = 0; __x < 3; __x++);
            int #lb = 7;
            long [] x [5];
            Boolean []ba[];
            enum Traffic {RED, YELLOW, GREEN}; }
    }

    What is the result? (Choose all that apply)

    1. Compilation succeeds
    2. Compilation fails due to an error on line 3
    3. Compilation fails due to an error on line 4
    4. Compilation fails due to an error on line 5
    5. Compilation fails due to an error on line 6
    6. Compilation fails due to an error on line 7
  12. Given
  13. public class TestDays {
        public enum Days { MON, TUE, WED };
        public static void main(String[] args) {
            for (Days d : Days.values())
                ;
            Days[] d2 = Days.values();
            System.out.println(d2[2]);
        }
    }

    What is the result? (Choose all that apply)

    1. TUE
    2. WED
    3. The output is unpredictable
    4. Compilation fails due to an error on line 2
    5. Compilation fails due to an error on line 4
    6. Compilation fails due to an error on line 6
    7. Compilation fails due to an error on line 7
  14. Given
  15. public class Frodo extends Hobbit {
        public static void main(String[] args) {
            Short myGold = 7;
            System.out.println(countGold(myGold, 6));
        }
    }
    class Hobbit {
        int countGold(int x, int y) {
            return x + y;
        }
    }

    What is the result?

    1. 13
    2. Compilation fails due to multiple errors
    3. Compilation fails due to an error on line 3
    4. Compilation fails due to an error on line 4
    5. Compilation fails due to an error on line 8
Prev Next

Comments