My Report

Java Programming Practice Test 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. How to get prints of shared object memory maps or heap memory maps for a given process?

2. Which of the following modifier means a particular variable cannot be accessed within the package?

3. Garbage Collection can be controlled by a program?

4. What will be the output of the following Java program?

    class box 
    {
        int width;
        int height;
        int length;
    } 
    class mainclass 
    {
        public static void main(String args[]) 
        {        
            box obj1 = new box();
            box obj2 = new box();
            obj1.height = 1;
            obj1.length = 2;
            obj1.width = 1;
            obj2 = obj1;
            System.out.println(obj2.height);
        } 
    }

5. Which of these statement is incorrect?

6. What is the return type of a method that does not return any value?

7. 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);     
        }
   }

8. What is true about a break?

9. What will be the output of the following Java code?

    class access
    {
        public int x;
 	private int y;
        void cal(int a, int b)
        {
            x =  a + 1;
            y =  b;
        }        
    }    
    public class access_specifier 
    {
        public static void main(String args[])
        {
            access obj = new access();   
            obj.cal(2, 3);
            System.out.println(obj.x + " " + obj.y);     
        }
   }

10. What will be the output of the following Java program?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int a = 5;
             int b = 10;
             first: 
             {
                second: 
                {
                   third: 
                   { 
                       if (a ==  b >> 1)
                           break second;
                   }
                   System.out.println(a);
                }
                System.out.println(b);
             }
        } 
    }

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.