Lara

Question Paper Core java Part-1(10-01-2017)

1.       Which options  are correct?

(A)Local variable always initialized to compile successfully

(B)Local variable should be initialized before use

(C)Local variables can be used in throughout class

(D) Two Local variable can have same name with different data type

(E)Multiple local variables of same data type can be declared in the same statement with comma as a separator

(F)Multiple local variable of same data type can be initialized with same value in the same statement

(G) local variable of if block can be used in else block

 

2.       Which are correct options

(A)class will be loading to the memory for every usage of the same class

(B) class will be loading to the memory only while first usage

(C)for every object creation class will be loading into the memory

(D)while starting java command all required classes will be loading

 

3.       Which are correct option options with respect to static variable

(A)while declaring itself it can be initialized with another same type of variable, which is already declared

(B)while declaring itself it can be initialized with any variable

(C)while declaring itself it can be initialized with any method return value

(D)while declaring itself it can be initialized with a method return value, which is having same return type of variable data type

 

4.       Which options are correct

(A)Assume super class already available in the memory while using subclass only sub class loading into memory

(IB)assume super class already available in the memory while using subclass both super class and subclass will be loading into the memory

(C)Assume super class not available in the memory, while using sub class both super class and sub class will be loading into memory

(D)Assume super class not available in the memory while using sub class only sub class will be loading into memory

 

5.       Which are correct options?

(A)while creating an object all constructor of the same class will be executing by default

(B)only specified constructor while creating an object by default

(C)always no arg constructor

(D) always first constructor

 

6.       Which are correct

(A)IIB blocks will executes only once for one object creation

(B)IIB blocks will executes based no of constructors while creating an object

       (C)IIB on order of object creation (one times for first object, 2 times for 2nd object, 3 time for 3rd       object)

(D)none

 

7.       Which are correct options?

(A)default value to Boolean is false

(B)default value to reference type is null

(C) default value to int is 0

(D)default value to double is 0

 

8.       Which are correct options

(A)by default we can create any no of object to one class

(B)we can assign any no of references to one object

(C)object can have references from different methods

(D)same reference can refer to multiple objects at the same time

 

9.       What are the correct options?

(A)first statement of a constructor is always super()

(B) first statement of a constructor is always this()

(C) first statement of a constructoris always super() and this()

(D)first statement of a constructor is always super() or this()

 

10.   What are the correct options?

(A)private members are not inherited

(B)default access access and protected access are same incase of usase

(C)default access and protected access are same in case of inheritance

(D)threr is no difference between protected and public incase of inheritance

 

11.   What are correct?

(A)abstract class can have any number of method

(B)abstract class can have any number of constructor

(C)abstract class should not have any constructor

(D)abstract class can be used for data type purpose

 

12.   Which are correct

(A)all interface member are public

(B)all interface member are abstract

(C)every interface in public default

(D)interface can extends any number of interface

 

13.   Which are currect

(A)inherited method can be overloaded

(B)inherited method can be overrided

(C)static method can be overloaded

(D)static method can be overrided

 

14.   Int i=128;

byte b=(byte)i;

(A)compile time error   (B)runtime error

(C)128                             (D)-128     (E)-127

 

15.   class A { }

class B extends A

class C extends   B

A a1=new C();

which options compiles and runs successfully

 

(A)B b1=a1;

(B)Object obj = a1;

(C)B b1 = (C)(B)a1;

(D)C c1 = (B)(C)a1;

16.   What is the output of this program

class A

{

       public static void main(String[] args)

       {

                       int i;

                       int j = 10 + i + (i = 30);

                       System.out.println(i);

                       System.out.println(j);

       }

}

(A)0                     (B)30

     40                        40

(C) 10                  (D)Compile time error

      10                 

 

 

17.   What is the output of this program

class B

    {

         public static void main(String[] args)

         {

            int i = 0;

            int j = i++  +  i  +  i--  +  i  +

                  i--  +  i++  +  i--  +  i  +

                  i++  +  i--  +  i+45  +  i++;

            System.out.println(i);

            System.out.println(j);

         }

    }

(A)0                   (B)0

      41                     -3

(C)0                   (D)compile time error

      42

18.   What is the output of this program?

class C

{

   public static void main(String[] args)

   {

         if(true && true)

         {

               System.out.println("from if");

         }

         System.out.println("end of main");

   }

}

 

(A)from if                  (B)end of main

      end of main              form if

(C)compile time error       (B)run time error

 

19.   What is the output of this program

class G

{

   public static void main(String[] args)

   {

         for(int i = 0; i > 0; i++)

         {

               System.out.println("loop:" + i);

         }

         System.out.println("main end");

   }

}

 

(A)loop: 0                                  (B)loop:1

     main end                                   main end

(C) loop:0                                   (D) main end

 

20.   What is the output of this program?

class E

{

   public static void main(String[] args)

   {

         int i = 0;

         while(i < 5);          

 

         {

               i++;

         }

        

        

         System.out.print(i +",");

   }

}

 

(A)1,2,3,4,5                                             (B)0,1,2,3,4

(C)compile success (run time error)   (D) running success (no output)

 

21.   What is the output of this program?

class G

{

   public static void main(String[] args)

   {

          int i=return;

         System.out.println("from main:" + i);

         return 100;

   }

}

 

(A)from main:0           (B) from main:100

(C)compile time error     (D) run time error

 

22.   What is the output of this program

class G

{

   static int i = 10;

   public static void main(String[] args)

   {    

         System.out.println(i);

         double i = 2.9;

         System.out.println(i);

         System.out.println(G.i);

   }

}  

(A)10                  (B) 10

   10                      2.9

0                             10

(C)compile time error  (D) run time error

 

23.   What is the output of this program

class G

{

   static int i;

   static int j = i;

   public static void main(String[] args)

   {

         System.out.println(i);

         System.out.println(j);

   }

}

(A)Run time error // line no 4

(B)Compile time error (initialize before usage)

(C)Printing with default value

(D)None of these

24.   What is the output of this program

class G

{

   static int i = 10;

   static int j = test();

   static int test()

   {

         return i;

   }

   public static void main(String[] args)

   {

         System.out.println(i);

         System.out.println(j);

   }

}

(A)10                (B)0

   10                   10

(C)10                 (D)0

   0                     0

 

25.   What is the output of this program  

class J

{

   static

   {

         System.out.println(i);

   }

   static int i;

   public static void main(String[] args)

   {

         System.out.println("done");

   }

}

(A)0                  (B)done

   done                  0

 

(C)done                  (D)compile time error     

26.   what is the output of this program

   package com.lara

   class A

   {

       public static void main(String[] args)

       {

            A a1 = new A();

            A a2 = a1;

            a1=10;

            a2=20;

            System.out.println(a1);

            System.out.println(a2);

        }

    }

(A)memory adderss of a1 and a2   (B)compile time error

(C)com.lara.memory address       (D)runtime error

 

27.   What is the output of this program

class E

{

   int i;

   void test()

   {

         System.out.println(this.i);

         this.i = 110;

   }

   public static void main(String[] args)

   {

         E e1 = new E();

         System.out.println(e1.i);

         e1.test();

         System.out.println(e1.i);

   }

}

 

(A)0               (B)memory address in hexadecimal

   0                 

   110               

(C)110              (D)0

   110                 110

0                            110

       

    

            

 

28.   What is the output of this program

class G

{

   static void test()

   {

         System.out.println(this);

   }

}

(A)memory address of class G    (B) memory address of test()

(C)run time error               (D) compile time error

 

29.   What is the output of this program

class Q

{

   int i;

   void test()

   {

         Q q1 = new Q();

         q1.i = i;

         System.out.println("test-a:" + q1.i);

         System.out.println("test-b:" + i);

   }

   public static void main(String[] args)

   {

         Q obj = new Q();

         obj.i = 20;

         obj.test();

   }

}

(A) test-a:20              (B)test-a:0

    test-b:20                 test-b:20

(C) test-a:0               (D)compile time error

Test-b:0

30.   What is the output of this program

class D

{

   int i = test1();

   int j = test1();

   int test1()

   {

         System.out.print("from test1:");

         System.out.print("i = " + i);

         System.out.println(",j = " + j);

         return 10;

   }

   public static void main(String[] args)

   {

         System.out.println("main begin");

         D d1 = new D();

  

         System.out.print(d1.i);

         System.out.println("," + d1.j);

        

   }

}

    (A) main begin              (B) main begin

       from test1:i = 0,j = 0       from test1:i=10,j = 0

       from test1:i = 10,j = 0      from test1:I = 10,j = 0

   10,10                        10,10

    (C) main begin                (D)main begin

        from test1:i = 0,j = 0       from test1:i = 0, j = 0

        from test1:i = 10,j = 0      from test1:I =10, j = 10

    0,0                          10,10

31.   What is the output of this program

class J

{

   static int x;

   x=20;

   public static void main(String[] args)

   {

         J obj = new J();

         System.out.println(x);

         System.out.println(J.x);

         System.out.println(obj.x);

   }

}

(A)20              (B)0

   20                 memory address of J class

20                 20

    (C)compile time error   (D)run time error

 

32.   What is the output of this program

class R

{

   R(int i)

   {

         System.out.println("R(int i)");

   }

   R(int i, int j)

   {

         System.out.println("R(int i, int j)");

   }

   public static void main(String[] args)

   {

         R r1 = new R(9, 10);

         System.out.println("done");

   }

}

(A)compile time error     (B)R(int i, int j)

                              done

 (C)R(int i)               (D)R(int i, int j)  

    R(int I, int j)           R(int i)

    done                      done      

 

 

                                                                                                                                                                                                                             

33.   What is the output of this program

class S

{

   int i;

 

   S(int i)

   {

         i = i;

   }

   public static void main(String[] args)

   {

         S s1 = new S(10);

         System.out.println(s1.i);

   }

}

(A)compile time error  (B)0

(C)10                  (D)run time error

 

34.   What is the output of this program

class I

{

   static int x;

}

class J extends I

{

   static int y;

   public static void main(String[] args)

   {

         System.out.println(J.x);

         System.out.println(J.y);

   }

}

(A)0                   (B)memory address of x

   0                      memory address of y

(C)compile time error  (D) run time error

 

 

35.   What is the output of this program

abstract class L

{

   abstract void test1();

}

class M extends L

{

   void test1()

   {

         System.out.println("from test1");

   }

   public static void main(String[] args)

   {

         //L obj1 = new L();

         M obj2 = new M();

         System.out.println("done");

   }

}

(A)compile time error   (B) run time error

(C)from test1           (D)done

   Done

36.   What is the output of this program

abstract class X

{

   X()

   {

         System.out.println("X()");

   }

}

abstract class Y extends X

{

   Y(int i)

   {

         System.out.println("Y(int)");

   }

}

class Z extends Y

{

   Z()

   {

         super(90);

         System.out.println("Z()");

   }

   public static void main(String[] args)

   {

         Z z1 = new Z();

         System.out.println("done");

   }

}

 

(A) X()          (B)Y()

    Y(int)          Z()

    Z()            Y(int)

done            done   

 

(C)compile time error

 

 

(D)run time error

 

 

37.   What is the output of this program

interface K

{

  

}

class L

{

   public static void main(String[] args)

   {

         K k1 = new K();

         System.out.println("done");

   }

}

 

(A)compile time error   (B)done

(C)run time error           (D)none

 

38.   What is the output of this program

interface D

{

   void test1();

}

class E

{

   public void test1()

   {

         System.out.println("from test1");

   }

}

class F extends E implements D

{

   public static void main(String[] args)

   {

         F f1 = new F();

         f1.test1();

         System.out.println("done");

   }

}

 

(A)from test1     (B)done

     done                    form test1

(C) done              (D)from test1

 

39.   What is the output of this program

class M

{

   void test()

   {

         System.out.println("from M.test");

   }

}

class N extends M

{

   void test()

   {

         System.out.println("from N.test begin");

         super.test();

         System.out.println("from N.test end");

   }

   public static void main(String[] args)

   {

         N n1 = new N();

         n1.test();

   }

}

 

(A)compile time error    (B)from M.test

                                                From N.test begin

                                               From N.test end

(C) from N.test begin   (D)from N.test begin

   from M.test            from N.test end

   from N.test end        from M.test

 

40.   What is the outout of this program

class B

{

   public static void main(String[] args)

   {

         short i = 500;

         int j = i;

         System.out.println(i);

         System.out.println(j);

         System.out.println("done");

   }

}

(A)compile time error   (B) run time error

(C)500                     (D)500.00

     500                           500.00

     done                         done

41.   What is the output of this program

class D

{

   public static void test(double d)

   {

         System.out.println("test:" + d);

   }

   public static void main(String[] args)

   {

         int i = 200;

         test(i);

   }

}

(A)d           (B)test:200

(C)test:200.0  (D)compile time error

 

42.   What is the output of this program

class D

{

   static float test()

   {

         int i = 200;

         return i;

   }

   public static void main(String[] args)

   {

         float f1 = test();

         System.out.println(f1);

   }

}

(A)200        (B)memory address of f1

(C)compile time error    (D)200.0

 

43.   What is the output of this program

class I

{

     static float test1(short b)

     {

                 return test2(b);

     }

     static long test2(int s)

     {

                 return s;

     }

     public static void main(String[] args)

     {

                 byte b = 20;

                 double d = test1(b);

                 System.out.println(d);

     }

}

(A)20     (B)20.0

(C)test1:20   (D)compile time error

 

44.   What is the output of this program

class D

 

{

   static void test(int i)

   {

         System.out.println("test");

   }

   public static void main(String[] args)

   {

         byte b = 20;

         test((int )250);

         System.out.println("DONE");

   }

}

(A)test            (B)done

   DONE               test

(C)compile time error   (D)done

 

45.   What is the output of this program

class P

{

     public static void main(String[] args)

     {

                 int i = 10;

                 byte b = (byte) i;

                 System.out.println(i);

                 System.out.println(b);

     }

}

(A)10                 (B)10

      10.0                   10

(C)10.0             (D)compile time error

10.10

 

46.   What is the output of this program

class D

{

   static void test(byte b)

   {

         System.out.println("from test:" + b);

   }

   public static void main(String[] args)

   {

         int i = 128;

         test((byte)i);

   }

}

(A)from test:128      (B)from test:-128

(C)from test:+128    (D)compile time error

 

47.   What is the output of this program

class T

{

     static int test()

     {

                 return 10.9;

     }

     public static void main(String[] args)

     {

                 System.out.println(test());

     }

}

(A)10.9     (B)test()

(C)compile time error   (D) run time error

 

48.   What is the output of this program

class D

{

   static byte test()

   {

         return (byte)-129;

   }

   public static void main(String[] args)

   {

         System.out.println(test());

   }

}

(A)129        (B)-129

(C) 128        (D)127

 

49.   What is the output of this program

class Z1

{

     public static void main(String[] args)

     {

                 double i = 90.0;

                 int j = (byte) (short) (long) i;

                 System.out.println(i);

     }

}

(A)90    (B)compile time error

(C)90.0   (D)0

 

50.   What is the output of this program

class V

{

   static void test1(B b1)

   {

   }

 

   static D test2()

   {

         return null;

   }

   public static void main(String[] args)

   {

         B b1 = new B();

         test1(b1);

         test1(new B());

         D d1 = test2();

         System.out.println("done");

   }

}

(A)done     (B)Exception

(C)compile time error   (D)Run time error

51.   What is the output of this program

class Z6

{

   public static void main(final String[] args)

   {

      args=null;

      System.out.println("done");

    }

}

(A)compile time error   (B)run time error

(C)  done                      (D)none

 

52.    What is the output of this program

class G

{

       public static void main(String[]args)

       {

                       final String s1=("abc");

                       s1="abc";

                       System.out.println("done");

                       }

}

(A)abc        (B)done

     done     

(C)compile time error   (D) run time error

 

53.   What is the output of this program

class Z1

{

   public static void main(String[]args)

   {

         final int[] x= new int[2];

         x[0]=100;

         x[1]=200;

         System.out.println("done");

         }

}

(A)compile time error   (B)run time error

(C)done                             (D)none

 

54.    What is the output of this program

    class Z9

    {

        public static void main(String[]args)

        {

            final String[] Y= new String[3];

            Y= new String[3];

            System.out.println("done");

         }

     }

(A)compile time error   (B) run time error

(C)done           (D) none

 

55.   What is the output of this program

class P

{

   int i=10;

   public static void main(String[] args)

   {

         final P p1= new P();

         p1.i = 10;

         System.out.println("done");

   }

}

(A)done                (B)compile time error

(C)run time error  (D)none

 

56.   What is the output of this program

abstract class P

{

    abstract final void test();

}

 

(A)run time error    (B)compile time error

 

57.   What is the output of this program

enum I

{

   test1,test2,test3;

}

class J

{

   public static void main(String[] args)

   {

         I ref1=I.test3;

         System.out.println(ref1);

         ref1=I.test1;

         System.out.println(ref1);

   }    

}

(A)ref1            (B)test1

     ref1                  test2

(C)test2           (D)test3

     test3                  test1

 

58.   What is the output of this program

class J

{

   enum En

   {

         CON1,CON2,CON3,CON4;

   }

   public static void main(String[] args)

   {

         En all[]=En.values();

         for(int i=0;i<all.length; i++)

         {

         System.out.println(all[i]);

         }

   }    

}

(A)done                                         (B) CON1,CON2,CON3,CON4,

(C)compile time error    (D)run time error

 

59.    What is the output of this program

class J

{

      public static void main(String[] args)

      {

            int i = 10;

            Integer obj = new Integer(i);

            int k = obj.intValue();

            System.out.println(i == k);

      }

}

(A)done        (B)false

(C)compile time error   (D)true

 

60.   What is the output of this program

class J

{

   public static void main(String[] args)

   {

         Integer obj1 = new Integer(90);

         Double obj2 = new Double(9.90);

         Character obj3 = new Character('t');

         Boolean obj4 = new Boolean(true);

 

         int i = obj1.intValue();

         double j = obj2.doubleValue();

         char k = obj3.charValue();

         boolean flag = obj4.booleanValue();

 

         System.out.println("done");

   }

}

(A)done    (B)compile time error 

(C)run time error  (D)true

 

61.   What is the output of this program

class J

{

   public static void main(String[] args)

   {

         String s1 = "34";

         Byte obj1 = new Byte(s1);

         Short obj2 = new Short(s1);

         Integer obj3 = new Integer(s1);

         Double obj4 = new Double(s1);

         Float obj5 = new Float(s1);

 

         byte b1 = obj1.byteValue();

         short s1 = obj2.shortValue();

         int i = obj3.intValue();

         double j = obj4.doubleValue();

         float k = obj5.floatValue();

 

         System.out.println("done");

   }

}

(A)done                  (B) compile time error

(C)run time error  (D)none of this

 

 

62.   What is the output of this program

class J

{

   public static void main(String[] args)

   {

         Integer obj1 = new Integer("abc");

         int i = obj1.intValue();

         System.out.println(i);

   }

}

 

(A)abc                 (B)123

(C)compile time error  (D) run time error

 

63.   What is the output of this program

class J

{

   public static void main(String[] args)

   {

         String s1 = "true";

         String s2 = "false";

         String s3 = "abc";

 

         Boolean obj1 = new Boolean(s1);

         Boolean obj2 = new Boolean(s2);

         Boolean obj3 = new Boolean(s3);

 

         boolean b1 = obj1.booleanValue();

         boolean b2 = obj2.booleanValue();

         boolean b3 = obj3.booleanValue();

         System.out.print(b1 + ”,”);

         System.out.print(b2 + ”,”);

         System.out.print(b3 + “,”);

   }

}

(A) true,false,false,    (B)true, false, abc

(C)false, false, false  (D)run time error

 

64.   What is the output of this program

class J

{

   public static void main(String[] args)

   {

         String s1 = "23";

 

         Integer obj1 = Integer.valueOf(s1);

         Double obj2 = Double.valueOf(s1);

        

         int i = obj1.intValue();

         double j = obj2.doubleValue();

 

         System.out.println(i);

         System.out.println(j);

   }

}

(A)23.0                            (B)23

      0                                     23.0

(C)compile time error   (D)23

                                               23

 

65.   What is the output of this program

class Q

{

       public static void main(String[] args)

       {

                       Boolean b1 = Boolean.valueOf(true);

                       Boolean b2 = Boolean.valueOf("true");

                       Boolean b3 = Boolean.valueOf("XYZ");

                      

                       boolean flag1 = b1.booleanValue();

                       boolean flag2 = b2.booleanValue();

                       boolean flag3 = b3.booleanValue();

 

                       System.out.println(flag1);

                       System.out.println(flag2);

                       System.out.println(flag3);

       }

}

(A)true         (B)false

true            true

flase          false

(C)flag1    (D)run time error

   flag2

   flag3

 

66.   Which wrapper class has only one constructor

(A)Integer          (B)Double

(C)Boolean      (D)Character

 

67.   In which version of JDK autoboxing and unboxing concept has been introduced?

(A)JDK1.4   (B)JDK1.5

(C)JDK1.6  (D)JDK1.8

 

68.   Which one is not a annotation

(A)@Target    (B)@Retention 

(C)@Inherited   (D)@Overload

 

69.   What is the output of this program

class G

{

   int i;

   public static void main(String[] args)

   {

         G obj = new G();

         System.out.println(obj.i);

   }

}

 

(A)0    (B)memory address of obj

(C)1    (D)compile time error

 

70.   What is the output of this program

class N

{

   class A

   {

   }

   static class B

   {

   }

   public static void main(String[] args)

   {

         A a1 = null;

         B b1 = null;

         System.out.println("done");

         System.out.println(a1);

   }

}

(A)done                         (B)done

    a1                                     null

(C)done                           (D)compile time error

    Memory address           

 

 

Answer Key Core Java part-1 (10-01-2017)

1.       B, E, F

2.       B

3.       A, D

4.       A, C

5.       B

6.       A

7.       B, D

8.       A, B, C

9.       D

10.   A,B

11.   B, D

12.   A, D

13.   A, B,C

14.   D

15.   B,C

16.   D

17.   C

18.   A

19.   D

20.   D

21.   C

22.   B

23.   C

24.   A

25.   D

26.   B

27.   A

28.   D

29.   A

30.   A

31.   C

32.   B

33.    B

34.   A

35.   D

36.   A

37.   A

38.   A

39.   C

40.   C

41.   C

42.   D

43.   B

44.   A

45.   B

46.   B

47.   C

48.   D

49.   C

50.   A

51.   A

52.   C

53.   C

54.   A

55.   A

56.   B

57.   D

58.   B

59.   D

60.   A

61.   B

62.   D

63.   A

64.   B

65.   A

66.   D

67.   B

68.   D

69.   A

70.   B