General Knowledge Quiz

1) Which of the following is true about Static Initialization Block?
a) Static Initialization Blocks are only used to initialize static fields of a class.
b) Static Initialization Block is the first block to be executed after class is loaded in the memory.
c) You can use static members of a class inside the Static Initialization Block.
d) All of the above.

2) Where are the static initialization blocks stored during initialization?
a) No Where.
b) Static Initialization Blocks are not stored in the memory.
c) They just come to stack, execute their task and leave the memory.
d) All of the above.


3)
class Any {
    static int i;
 
    static
    {
        System.out.println(10);
 
        i = 50;
    }
}
 
public class Main2 {
    static
    {
        System.out.println(20);
    }
 
    public static void main(String[] args)
    {
        System.out.println(30);
 
        System.out.println(Any.i);
    }
}
a) Does not compile
b) 20
30
10
50
c) 30
d) 20
100

4) Can a lock be acquired on a class?
a) No
b) Sometimes
c) Yes
d) This lock is acquired on the class's Class object.
e) Both c) and d)

5) Which java.util classes and interfaces support event handling?
a) The ObjectEventObject class
b) The Event class
c) EventListener interface
d) None of the above
e) Both a) and c)

6) Wrapped classes are classes that are _____________.
a) Abstract classes
b) Interface classes
c) Composite classes
d) Wrapped classes are classes that allow primitive types to be accessed as object .

7) Are wrapper objects immutable?
a) All of the java.lang package wrapper classes are immutable
b) Half of the java.lang package wrapper classes are immutable
c) Only one of the java.lang package wrapper classes ais immutable
d) None of the above.

8) What is the immediate superclass of the Applet class?
a) Window
b) Panel
c) Dialog
d) None of the above.

9) What is the immediate superclass of the Dialog class?
a) Window
b) Panel
c) Dialog
d) None of the above.

10) What class is the top of the AWT event hierarchy?
a) Window.Event
b) Panel.Event
c) Dialog.Event
d) java.awt.AWTEvent.

11) What is a Java inner class or nested class?
a) There is no Inner Class in Java.
b) An Inner Class in Java is a Local Class.
c) Is a class which is declared inside the class or interface.
d) Is a class which is declared a block of code.

12) Can an anonymous class be declared as implementing an interface and extending a class? or extend a superclass, but may not be declared to do both.
a) An anonymous class may implement an interface.
b) An anonymous class may extend a superclass.
c) An anonymous class may implement an interface and extend a superclass.
d) a) or b).

13) What is the immediate superclass of Menu?
a) Window
b) Panel
c) MenuItem
d) Popup Menu.

14) What is the GregorianCalendar class?
a) The GregorianCalendar class provides support for traditional Western calendars.
b) The GregorianCalendar class provides internationalization support support.
c) The GregorianCalendar class is te same as the Date class.
d) All of the above.

15) What is the purpose of the Runtime class? The purpose of the Runtime class is to provide access to the Java runtime system.
a) The purpose of the Runtime class is to provide access to the system.
b) The purpose of the Runtime class is to provide access to the Java run() method.
c) The purpose of the Runtime class is to provide access to the Java runtime system.
d) The purpose of the Runtime class is to provide access to the Java init() method..

16) What must a class do to implement an interface?
a) It must provide all of the methods in the interface and identify the interface in its implements clause.
b) It must provide all of the methods it is overriding.
c) All of the above
d) None ofthe above.

17) Which class is extended by all other classes?
a) The Main class is extended by all other classes.
b) The Interface class is extended by all other classes.
c) The Abstract class is extended by all other classes.
d) The Object class is extended by all other classes.

18) Does a class inherit the constructors of its superclass?
a) A class does not inherit the constructors of its superclass.
b) A class inherits the constructors of its superclass.
c) A class inherits the default constructor of its superclass.
d) A class inherits the package constructor of its superclass. .

19) Is a class a subclass of itself?
a) A class is a super class of itself.
b) A class is a subclass of itself.
c) A class is a System class of itself.
d) None of the above.

20) What modifiers can be used with a local inner class?
a) A local inner class may be private.
b) A local inner class may be public.
c) A local inner class may be final or abstract.
d) A local inner class may be protected.

21) What is the purpose of the File class? The File class is used to create objects that provide access to the files and directories of a local file system.
a) The File class is used to create objects that provide access to only the files of a local file system.
b) The File class is used to create objects that provide access to only the directories of a local file system.
c) The File class is used to create objects that provide access to the files and directories of a local file system.
d) None of the above.

22) When does the Java compiler provide a default constructor for a class?
a) The Java compiler provides a default constructor for a class when the provided constructor fails during program loading.
b) The Java compiler provides a default constructor for a class does not compile.
c) The Java compiler provides a default constructor for a class when there is an exception during execution.
d) The Java compiler provides a default constructor for a class if no other constructors are provided.

23) Can a singleton class be subclassed?
a) When you use the ternary modifier on the constructor.
b) Extending a singleton class would no longer make it a singleton pattern.
c) When you use the public modifier on the constructor.
d) All of the above

24) Can an abstract class be final?
a) An abstract class can be declared as final.
b) An abstract class can not be declared as final.
c) Sometimes an abstract class can be declared as final.
d) All of the above.

25) What modifiers may be used with a top-level class?
a) A top-level class may be public, abstract, or final.
b) A top-level class may be private.
c) A top-level class may be protected.
d) None of the above.

26) What is it called when class has references to objects of other classes as members.
a) This is called proposition and is sometimes referred to as a has-a relationship.
b) This is called supposition and is sometimes referred to as a has-a relationship.
c) This is called composition and is sometimes referred to as a has-a relationship.
d) This is called a pattern and is sometimes referred to as a has-a relationship.

27) What is the difference between abstract class and interface?
a) An abstract class can have abstract and non-abstract methods.
b) An interface can only have abstract methods.
c) An abstract class can have static methods but an interface cannot have static methods.
d) Abstract class can have constructors but an interface cannot have constructors.
e) All of the above.

28) Which access modifiers can be applied to the inner classes?
a) public ,private.
b) abstract, final.
c) protected.
d) All of the above. .

29) What is an adapter class?
a) An adapter class provides the default implementation of all methods in an event listener interface.
b) An adapter class provides the default implementation of all methods in an abstract event listener.
c) An adapter class provides the default implementation of all classes in an event listener composite class.
d) All of the above.

30) What is the stored in the object obj in following lines of code?
   box obj;
a) Address of the allocated memory of object.
b) NULL
c) Garbage
d) Any arbitrary pointer.

31) Which of these keywords is used to make a class?
a) int
b) class
c) struct
d) None of the above.

32) Which of the following is a valid declaration of an object of class Clock
a) Clock obj = new Clock;
b) obj = new Clock();
c) Clock obj = new Clock();
d) new Clock obj;.

33) Which of these operators is used to allocate memory for an object?
a) alloc
b) new
c) super
d) malloc.

34) What is the output of this program?
  class Main2 {

     public static void main(String args[]) {

        int x = 9;

        if (x == 9) { 

           int x = 8;

           System.out.println(x);

        }
     } 

  } 
a) Compilation error
b) 8
c) 9
d) Runtime error.

35) Considering the following code, which of the following statements is correct?
class Any {
   int i = 10;
   public void msg(){System.out.println("Hello from Any");}
}
 
class Begin extends Any {
   int i = 20;
   public void msg(){System.out.println("Hello from Begin");}
}
 
public class Four
{
    public static void main(String[] args) {
        Any a = new Begin();
 
        System.out.println(a.i); 
        a.msg()  ;
    }
}
a) Public method is accessible only to subclasses of its parent class
b) Public method can be accessed by calling object of the public class.
c) Public method can only be called by object of its class.
d) Public method is accessible to all other classes in the hierarchy.

Quiz script provided by
Java Total Application Works