My Report (&Account)

Java Online Test


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

Here is the complete list of test quizzes on Java.

1. Default value of autoFlush attribute is?

Question 1 of 50 (sanfoundry.com)

2. What is true of final class?

Question 2 of 50 (sanfoundry.com)

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

public class Shape
{
	public int area()
       {
		return 1;
	}
}
public class Square extends Shape
{
	public int area()
       {
		return 2;
	}
}
public class Rectangle extends Shape
{
	public int area()
       {
		return 3;
	}
}
Class Main{
    public static void main(String[] args)
    {
	        Shape square = new Square();
     	 Shape rect = new Rectangle();
    	 square = rect;
    	 System.out.println(square.area());
    }
}

Question 3 of 50 (sanfoundry.com)

4. What type of protocol is HTTP?

Question 4 of 50 (sanfoundry.com)

5. Which of these methods can be used to obtain the reference to the container that generated a ContainerEvent?

Question 5 of 50 (sanfoundry.com)

6. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?

Question 6 of 50 (sanfoundry.com)

7. Which of these package is used for remote method invocation?

Question 7 of 50 (sanfoundry.com)

8. Which class is a library of functions to perform arithmetic operations of BigInteger and BigDecimal?

Question 8 of 50 (sanfoundry.com)

9. What is the range of short data type in Java?

Question 9 of 50 (sanfoundry.com)

10. Which of these method of class StringBuffer is used to find the length of current character sequence?

Question 10 of 50 (sanfoundry.com)

11. What is the maximum size of cookie?

Question 11 of 50 (sanfoundry.com)

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

   
    class isNaN_output 
    {
        public static void main(String args[]) 
        {
            Double d = new Double(1 / 0.);  
            boolean x = d.isNaN();
            System.out.print(x);
        }
    }

Question 12 of 50 (sanfoundry.com)

13. What are generic methods?

Question 13 of 50 (sanfoundry.com)

14. Which of these method is a rounding function of Math class?

Question 14 of 50 (sanfoundry.com)

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

 
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = s1.replace('l','w');
           System.out.println(s2);
        }
    }

Question 15 of 50 (sanfoundry.com)

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

 
    class evaluate 
    {
        public static void main(String args[]) 
            {
	        int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
	        int n = 6;
                n = arr[arr[n] / 2];
	        System.out.println(arr[n] / 2);
            } 
    }

Question 16 of 50 (sanfoundry.com)

17. Which of these constructors is used to create an empty String object?

Question 17 of 50 (sanfoundry.com)

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

    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 18 of 50 (sanfoundry.com)

19. Which of the following classes can catch all exceptions which cannot be caught?

Question 19 of 50 (sanfoundry.com)

20. Which of these methods of Character wrapper can be used to obtain the char value contained in Character object.

Question 20 of 50 (sanfoundry.com)

21. Which of these data member of HttpResponse class is used to store the response from an http server?

Question 21 of 50 (sanfoundry.com)

22. Which method returns the elements of Enum class?

Question 22 of 50 (sanfoundry.com)

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

 
    class newthread extends Thread
    {
	Thread t;
	String name;
	newthread(String threadname)
        {
	    name = threadname;
	    t = new Thread(this,name);
	    t.start();
	}
	public void run()
        {
        }
     
    }
    class multithreaded_programing
    {
        public static void main(String args[])
        {
	    newthread obj1 = 	 new newthread("one");
	    newthread obj2 =	 new newthread("two");
            try
            {
                obj1.t.wait();	
                System.out.print(obj1.t.isAlive());
            }
            catch(Exception e)
            {
	    System.out.print("Main thread interrupted");
            }
        }
    }

Question 23 of 50 (sanfoundry.com)

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

 
    import java.util.*;
    class Bitset 
    {
        public static void main(String args[]) 
        {
            BitSet obj = new BitSet(5);
            for (int i = 0; i < 5; ++i)
                obj.set(i);
            obj.clear(2);
            System.out.print(obj);
        }
    }

Question 24 of 50 (sanfoundry.com)

25. Which of these keywords is used to refer to member of base class from a subclass?

Question 25 of 50 (sanfoundry.com)

26. Which of these methods of Byte wrapper can be used to obtain Byte object from a string?

Question 26 of 50 (sanfoundry.com)

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

 
    import java.net.*;
    class networking 
    {
        public static void main(String[] args) throws Exception 
        {
            URL obj = new URL("https://www.sanfoundry.com/javamcq");
            URLConnection obj1 = obj.openConnection();
            System.out.print(obj1.getContentType());
        }
    }

Note: Host URL is written in html and simple text.

Question 27 of 50 (sanfoundry.com)

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

 
    import java.util.*;
    class Collection_iterators 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    Collections.shuffle(list);
            i.next();
            i.remove();
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }

Question 28 of 50 (sanfoundry.com)

29. Which of these methods can be used to get reference to a component that was removed from a container?

Question 29 of 50 (sanfoundry.com)

30. Which of these packages contains abstract keyword?

Question 30 of 50 (sanfoundry.com)

31. When destroy() method of a filter is called?

Question 31 of 50 (sanfoundry.com)

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

 
    class array_output 
    {
        public static void main(String args[]) 
        {
            int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
            int sum = 0;
            for (int i = 0; i < 3; ++i)
                for (int j = 0; j <  3 ; ++j)
                    sum = sum + array_variable[i][j];
            System.out.print(sum / 5);
        } 
    }

Question 32 of 50 (sanfoundry.com)

33. Which of these methods are used to read in from file?

Question 33 of 50 (sanfoundry.com)

34. Which of these method of Double wrapper can be used to check whether a given value is infinite or not?

Question 34 of 50 (sanfoundry.com)

35. Which of the below is false about java coding?

Question 35 of 50 (sanfoundry.com)

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

 
    class multithreaded_programing
    {
        public static void main(String args[])
        {
            Thread t = Thread.currentThread();
            t.setName("New Thread");
            System.out.println(t);        
        }
    }

Question 36 of 50 (sanfoundry.com)

37. What is the alternative of using finally to close resource?

Question 37 of 50 (sanfoundry.com)

38. Which of the following is not a decision making statement?

Question 38 of 50 (sanfoundry.com)

39. Which of these classes encapsulate runtime environment?

Question 39 of 50 (sanfoundry.com)

40. Which of these are constants defined in WindowEvent class?

Question 40 of 50 (sanfoundry.com)

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

    
    class output 
    {
        public static void main(String args[])
        {
            String a = "hello i love java";
            System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));
        }
    }

Question 41 of 50 (sanfoundry.com)

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

Question 42 of 50 (sanfoundry.com)

43. Which of the below is invalid identifier with the main method?

Question 43 of 50 (sanfoundry.com)

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

 
import java.io.*;
public class filesinputoutput
{
    public static void main(String[] args)
    {
        String obj  = "abc";
        byte b[] = obj.getBytes();
        ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
        for (int i = 0; i < 2; ++ i)
        {
            int c;
            while((c = obj1.read()) != -1)
            {
                if(i == 0)
                {
                    System.out.print(Character.toUpperCase((char)c));
                }
                System.out.print((char)c);
            }
        }
    }
}	

Question 44 of 50 (sanfoundry.com)

45. Which of these is a method of ObjectInput interface used to deserialize an object from a stream?

Question 45 of 50 (sanfoundry.com)

46. Which of these methods can be used to obtain a static array from an ArrayList object?

Question 46 of 50 (sanfoundry.com)

47. Which of this package is used for analyzing code during run-time?

Question 47 of 50 (sanfoundry.com)

48. Which of these packages contain all the collection classes?

Question 48 of 50 (sanfoundry.com)

49. Thread priority in Java is?

Question 49 of 50 (sanfoundry.com)

50. Which one of the following is a class loader?

Question 50 of 50 (sanfoundry.com)


 

Topic wise Test Quizzes on Java

Java tests, quizzes, and exams are great ways to learn and test your Java programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on Java basics, oops, arrays, exceptions, constructors, collections, multithreading, JDBC, and advanced java. Start the Java online test now!



Java Programming Certification Test

Java Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Java Programming Internship Test

If you scored either Grade A* or Grade A in our Java Programming Internship Test, then you can apply for Internship at Sanfoundry in Java Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Java Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on Java Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
Manish Bhojasia – Founder & CTO at Sanfoundry

I’m Manish, Founder & CTO at Sanfoundry, with 25+ years of experience across Linux systems, SAN technologies, advanced C programming, and building large-scale, performance-driven learning and certification platforms focused on clear skill validation.

LinkedIn  ·  YouTube MasterClass  ·  Telegram Classes  ·  Career Guidance & Conversations