• JAVA Quiz

    Instructions For Quiz

    • This Mock Test has 10 Questions
    • Each Question is of 1 marks so total 10 marks
    • Multiple Choice Questions with only ONE valid answer
  • 2)What will happen if you try to compile and run the following code ?

    public class MyClass {
    public static void main(String arguments[]){ amethod(arguments); }
    public void amethod(String[] arguments) {
    System.out.println(arguments);
    System.out.println(arguments[1]);
    }
    }

  • 4) What will be printed out if this code is run with the following command line?

    java myprog good morning public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]); } }

  • 6 )What will happen if you try to compile and run the following code?

    public class Q { public static void main(String argv[]){ int anar[]=new int[]{1,2,3}; System.out.println(anar[1]); } }
     

  • 7) What will be printed out if you attempt to compile and run the following code?

    int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); }

  • 8) What will happen if you attempt to compile and run the following code?

    class Base {} class Sub extends Base {} class Sub2 extends Base {} public class CEx{ public static void main(String argv[]){ Base b=new Base(); Sub s=(Sub) b; } }

  • 9)What will happen when you attempt to compile and run the following code?

    public class Tux extends Thread{ static String sName = "vandeleur"; public static void main(String argv[]){ Tux t = new Tux(); t.piggy(sName); System.out.println(sName); } public void piggy(String sName){ sName = sName + " wiggy"; start(); } public void run(){ for(int i=0;i < 4; i++){ sName = sName + " " + i; } } }

  • 10) What will be output by the following code?

    public class MyFor{ public static void main(String argv[]){ int i; int j; outer: for (i=1;i

  • Should be Empty: