My Report

Java Programming Mock Test 1


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 code?

 
    class multidimention_array 
    {
        public static void main(String args[])
        {
            int arr[][] = new int[3][];
            arr[0] = new int[1];
            arr[1] = new int[2];
            arr[2] = new int[3];               
	    int sum = 0;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    arr[i][j] = j + 1;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    sum + = arr[i][j];
	    System.out.print(sum); 	
        } 
    }

Question 1 of 10

Question 2 of 10

2. Which of these literals can be contained in float data type variable?

Question 2 of 10

Question 3 of 10

3. What will be the output of the following Java code snippet?

enum Enums
{
    A, B, C;
     
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

Question 3 of 10

Question 4 of 10

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

 
    class A 
    {
        final public int calculate(int a, int b) { return 1; } 
    } 
    class B extends A 
    { 
        public int calculate(int a, int b) { return 2; } 
    } 
     public class output 
     {
        public static void main(String args[]) 
        { 
            B object = new B(); 
            System.out.print("b is " + b.calculate(0, 1));  
        } 
    }

Question 4 of 10

Question 5 of 10

5. Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?

Question 5 of 10

Question 6 of 10

6. What will be the output of the following Java program, if we run as "java main_arguments 1 2 3"?

 
    class main_arguments 
    {
        public static void main(String [] args) 
        {
            String [][] argument = new String[2][2];
            int x;
            argument[0] = args;
            x = argument[0].length;
            for (int y = 0; y < x; y++) 
                System.out.print(" " + argument[0][y]);              
        }
    }

Question 6 of 10

Question 7 of 10

7. What is the replacement of joda time library in java 8?

Question 7 of 10

Question 8 of 10

8. What is the type of variable 'b' and 'd' in the following Java snippet?

int a[], b;
int []c, d;

Question 8 of 10

Question 9 of 10

9. Which of the following is the advantage of BigDecimal over double?

Question 9 of 10

Question 10 of 10

10. Which of the following are legal lines of Java code?

   1. int w = (int)888.8;
   2. byte x = (byte)100L;
   3. long y = (byte)100;
   4. byte z = (byte)100L;

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.