Tuesday, July 13, 2021

Java Quiz-3

Java Multiple Choice Questions


1. Which of these can not be used for a variable name in Java?

A.identifier
B.keyword
C.identifier and keyword both
D.none


2. Abstraction in Java can be achieved by using ________________

A.Abstract classes
B.interfaces
C.Abstract classes and interfaces both
D.packages and abstract classes


3. ______________ class members are the members of the class which do not belong to any instance of that class.

A.public
B.private
C.static
D.final


4. Static variable of a class can be accessed using _____________________ syntax.

A.ObjectName.staticVarName
B.ClassName.staticVarName
C.ObjectName.ClassName
D.staticVarName.className


5. public static final declared variables are ____________

A.global variables
B.global constants
C.not accessible
D.not possible


6. Which statement is true about static members of a class?

A.Static methods can directly access static variables of the class and manipulate them.
B.Static members can not access non static members(instance variables or instance methods)
C.Static methods can’t use this or super references.
D.All of the above


7. What is the output of the following program?

public class UI {
	static int i = 1;
	public static void main(String args[])
	{
	System.out.println(i+" , ");
	m(i);
	System.out.println(i);
	}
	public static void m(int i)
	{
	i += 2;
	}
}
A.1,3
B.3,1
C.1,1
D.1,0


8. What is the output of the following program?

public class UI {
	static int i = 1;
	public static void main(String args[])
	{
	System.out.println(i+" , ");
	m(i);
	System.out.println(i);
	}
	public static void m(int i)
	{
	i += 2;
	}
}
A.1,3
B.3,1
C.1,1
D.Error


9. Which statement is false

A.Static members of a class are shared among all instances of that class
B.Each instance of the class have its own static members
C.A non static method can be called inside a static method
D.A class can have static variables and static methods


10. What will be the output of the program?

public class UI {

    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A"); 
        }  
        catch (Exception ex) 
        {
            System.out.print("B");  
        } 
        finally 
        {
            System.out.print("C"); 
        } 
        System.out.print("D"); 
    }  
    public static void badMethod() 
    {
        throw new Error(); /* Line 22 */
    }

}
A.ABCD
B.Compilation Failure
C.C is printed before exiting with an error message.
D.BC is printed before exiting with an error message.


11. What will be the output of the program?

public class UI {

    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A");  
        } 
        catch (RuntimeException ex) /* Line 10 */
        { 
            System.out.print("B"); 
        } 
        catch (Exception ex1) 
        { 
            System.out.print("C"); 
        } 
        finally 
        {
            System.out.print("D"); 
        } 
        System.out.print("E"); 
    } 
    public static void badMethod() 
    { 
        throw new RuntimeException(); 
    } 
}
A.BD
B.BCD
C.BDE
D.BCDE