My Report

Java Programming Practice Test 3


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. What will be the output of the following Java program?

    class box 
    {
        int width;
        int height;
        int length;
        int volume;
        void volume() 
        {
            volume = width * height * length;
        } 
        void volume(int x) 
        {
            volume = x;
        }
    }    
    class Output 
    { 
        public static void main(String args[]) 
        {
            box obj = new box();
            obj.height = 1;
            obj.length = 5;
            obj.width = 5;
            obj.volume(5);
            System.out.println(obj.volume);        
        } 
    }

2. What will be the output of the following Java program, Command line execution is done as - "java Output command Line 10 A b 4 N"?

    class Output 
    {
        public static void main(String args[]) 
        {
            System.out.print((int)args[2] * 2);
        }
    }

3. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

4. Which class allows parsing of command line arguments?

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

 
    class Output 
    {
        public static void main(String args[])
        {
             Object obj = new Object();
	     System.out.print(obj.getclass());
        }
    }

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

    class output 
    {
        public static void main(String args[])
        {
            char c[]={'a', '1', 'b' ,' ' ,'A' , '0'};
            for (int i = 0; i < 5; ++i)
            {
                   if(Character.isDigit(c[i]))
                       System.out.println(c[i]+" is a digit");
                   if(Character.isWhitespace(c[i]))
                       System.out.println(c[i]+" is a Whitespace character");
                   if(Character.isUpperCase(c[i]))
                       System.out.println(c[i]+" is an Upper case Letter");
                   if(Character.isLowerCase(c[i]))
                       System.out.println(c[i]+" is a lower case Letter");
               i=i+3;
            }
        }
    }

7. Which of these packages contains the exception Stack Overflow in Java?

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

 
    class recursion 
    {
        int fact(int n) 
        {
            int result;
            if (n == 1)
                return 1;
            result = fact(n - 1) * n;
            return result;
        }
    } 
    class Output 
    {
        public static void main(String args[]) 
        {
            recursion obj = new recursion() ;
            System.out.print(obj.fact(5));
        }
    }

9. Using which of the following, multiple inheritance in Java can be implemented?

10. Which of these packages contains abstract keyword?


 

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.