243). Which of these keywords is used to prevent content of a variable from being modified?

[A]final
[B]last
[C]constant
[D]static

Show Answer

245). Which of the following statements are incorrect?

[A] static methods can call other static methods only
[B]static methods must only access static data
[C] static methods can not refer to this or super in any way
[D] when object of class is declared, each object contains its own copy of static variables

Show Answer

246). Which of the following statements are incorrect?

[A]Variables declared as final occupy memory
[B]final variable must be initialized at the time of declaration
[C]Arrays in java are implemented as an object
[D]All arrays contain an attribute-length which contains the number of elements stored in the array

Show Answer

247). Which of these methods must be made static?

[A]main()
[B]delete()
[C] run()
[D]finalize()

Show Answer

248). What will be the output of the following Java program?
    class access
    {
        public int x;
 	static int y;
        void cal(int a, int b)
        {
            x +=  a ;
            y +=  b;
        }        
    }    
    class static_specifier 
    {
        public static void main(String args[])
        {
            access obj1 = new access();
            access obj2 = new access();   
            obj1.x = 0;
            obj1.y = 0;
            obj1.cal(1, 2);
            obj2.x = 0;
            obj2.cal(2, 3);
            System.out.println(obj1.x + " " + obj2.y);     
        }
   }

[A]1 2
[B]2 3
[C]3 2
[D]1 5

Show Answer

249). What will be the output of the following Java program?
    class access
    {
       static int x;
       void increment()
       {
           x++;
       }   
     }   
    class static_use 
    {
        public static void main(String args[])
        {
            access obj1 = new access();
            access obj2 = new access();
            obj1.x = 0;   
            obj1.increment();
            obj2.increment();
            System.out.println(obj1.x + " " + obj2.x);
         }
   }

[A]1 2
[B]1 1
[C]2 2
[D] Compilation Error

Show Answer

250). What will be the output of the following Java program?
    class static_out 
    {
        static int x;
 	static int y;
        void add(int a , int b)
        {
            x = a + b;
            y = x + b;
        }
    }    
    class static_use 
    {
        public static void main(String args[])
        {
            static_out obj1 = new static_out();
            static_out obj2 = new static_out();   
            int a = 2;
            obj1.add(a, a + 1);
            obj2.add(5, a);
            System.out.println(obj1.x + " " + obj2.y);     
        }
   }

[A]7 7
[B] 6 6
[C] 7 9
[D]9 7

Show Answer

251). What will be the output of the following Java program?
    class Output 
    {
        public static void main(String args[])
        {
            int arr[] = {1, 2, 3, 4, 5};
            for ( int i = 0; i < arr.length - 2; ++i)
                System.out.println(arr[i] + " ");
        } 
    }

[A] 1 2
[B] 1 2 3
[C]1 2 3 4
[D]1 2 3 4 5

Show Answer

252). What will be the output of the following Java program?
    class Output 
    {
        public static void main(String args[])
        {
            int a1[] = new int[10];
            int a2[] = {1, 2, 3, 4, 5};
            System.out.println(a1.length + " " + a2.length);
        } 
    }

[A]10 5
[B]5 10
[C]0 10
[D] 0 5

Show Answer