My Report

Java Programming Mock Test 9


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

Question 1 of 10

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

   
    package pkg;
    class display 
    {
        int x;
        void show() 
        {
            if (x > 1)
                System.out.print(x + " ");
        }
    }
    class packages 
    {
        public static void main(String args[]) 
        {
            display[] arr=new display[3];
            for(int i=0;i<3;i++)
                arr[i]=new display();
            arr[0].x = 0;      
            arr[1].x = 1;
            arr[2].x = 2;
            for (int i = 0; i < 3; ++i)
                arr[i].show();
         }
    }

Note : packages.class file is in directory pkg;

Question 1 of 10

Question 2 of 10

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

    import java.util.*;
    public class genericstack <E>
    {
        Stack <E> stk = new Stack <E>();
	public void push(E obj) 
        {
            stk.push(obj);
	}
	public E pop() 
        {
            E obj = stk.pop();
	    return obj;
	}
    }
    class Output
    {
        public static void main(String args[])
        {
            genericstack <String> gs = new genericstack<String>();
            gs.push("Hello");
            System.out.println(gs.pop());
        }
    }

Question 2 of 10

Question 3 of 10

3. Which of these instance cannot be created?

Question 3 of 10

Question 4 of 10

4. How can we delete all files in a directory?

Question 4 of 10

Question 5 of 10

5. Which of these types cannot be used to initiate a generic type?

Question 5 of 10

Question 6 of 10

6. What does Liskov substitution principle specify?

Question 6 of 10

Question 7 of 10

7. Which of these is an correct way making a list that is upper bounded by class Number?

Question 7 of 10

Question 8 of 10

8. What happens when a constructor is defined for an interface?

Question 8 of 10

Question 9 of 10

9. Which of these type parameters is used for a generic methods to return and accept a number?

Question 9 of 10

Question 10 of 10

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

    import java.util.*;
    public class genericstack <E>
    {
        Stack <E> stk = new Stack <E>();
	public void push(E obj)
        {
            stk.push(obj);
	}
        public E pop()
        {
            E obj = stk.pop();
	    return obj;
	}
    }
    class Output
    {
        public static void main(String args[])
        {
            genericstack <Integer> gs = new genericstack<Integer>();
            gs.push(36);
            System.out.println(gs.pop());
        }
    }

Question 10 of 10


 

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.