Launch your tech mastery with us—your coding journey starts now!

CORE JAVA MCQs with Answer

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

a) -128 to 127    

b) -32768 to 32767          

c) -2147483648 to 2147483647    

d) -5000 TO 5000

 

  1. What is the range of byte data type in Java?  

a) -128 to 127    

b) -32768 to 32767          

c) -2147483648 to 2147483647    

d) -5000 TO 5000

               

  1. An expression involving byte, int, and literal numbers is promoted to which of these?              

a) int    

b) long 

c) byte 

d) float

 

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

a) -1.7e+308      

b) -3.4e+038      

c) +1.7e+308     

d) -3.4e+050

 

  1. Which data type value is returned by all transcendental math functions?         

a) int     

b) float

c) double            

d)long

 

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

    class increment {                                                         

      public static void main(String args[])                                                 

         {                                                                    

             int g = 3;                                                 

              System.out.print(++g * 8);                                                           

         }                                                    

       }      

a) 25     

b) 24     

c) 32      

d) 33     

 

  1. What is the numerical range of a char data type in Java?          

a) -128 to 127    

b) 0 to 256          

c) 0 to 32767      

d) 0 to 65535

 

  1. Which of these coding types is used for data type characters in Java?

a) ASCII

b) ISO-LATIN-1 

c) UNICODE       

d) CODE

 

  1. Which of these values can a boolean variable contain?             

a) True & False

b) 0 & 1                

c) Any integer value       

d) true

 

  1. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?      

a) ASCII               

b) ISO-LATIN-1 

c) LATIN1            

d) ASCII and ISO-LATIN1

 

  1. Which one is a valid declaration of a boolean?            

a) boolean b1 = 1;           

b) boolean b2 = ‘false’; 

c) boolean b3 = false;   

d) boolean b4 = ‘true’

 

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

     class booloperators {                                                                

        public static void main(String args[])                                                                               

         {                                                                    

             boolean var1 = true;                                                                         

          boolean var2 = false;                                                                           

          System.out.println((var1 & var2));                                                                

         }                                                                    

    }

a) 0        

b) 1       

c) true  

d) false

 

  1. Which of these is long data type literal?         

a) 0x99fffL          

b) ABCDEFG      

c) 0x99fffa          

d) 99671246

 

  1. Which of these can be returned by the operator &?

a) Integer           

b) Boolean         

c) Character       

d) Integer or Boolean

 

  1. Literals in java must be appended by which of these?             

a) L        

b) l         

c) D       

d) L and I

 

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

a) identifier       

b) keyword        

c) identifier & keyword

d) constant

 

  1. How is Date stored in database?       

a) java.sql.Date

b) java.util.Date               

c) java.sql.DateTime      

d) java.util.DateTime

 

  1. What does LocalTime represent?     

a) Date without time     

b) Time without Date   

c) Date and Time             

d) Date and Time with timezone

 

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

     class c                                                              

     {                                                        

         public void main( String[] args )                                                        

         {                                                    

             System.out.println( “Hello” + args[0] );                                                    

         }                                                    

     }        

a) Hello c             

b) Hello

c) Hello world   

d) Runtime Error

                                               

 20.Which of these operators is used to allocate memory to array variable in Java?           

a) malloc             

b) alloc 

c) new 

d) new malloc

 

  1. Which of these is an incorrect array declaration?       

a) int arr[] = new int[5] 

b) int [] arr = new int[5]

c) int arr[] = new int[5] 

d) int arr[] = int [5] new

 

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

    int arr[] = new int [5];                                                

    System.out.print(arr);                              

a) 0        

b) value stored in arr[0]

c) 00000               

d) Class name@ hashcode in hexadecimal form

                               

  1. Which of these is an incorrect Statement?   

a) It is necessary to use new operator to initialize an array         

b) Array can be initialized using comma separated expressions surrounded by curly braces          

c) Array can be initialized when they are declared            

d) Array used curly braces

 

  1. Which of these is necessary to specify at time of array initialization?

a) Row 

b) Column          

c) Both Row and Column             

d) Table

 

  1. 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);                                                    

             }                                                

     }        

a) 3        

b) 0       

c) 6        

d) 1

                                               

  1. Which of the following can be operands of arithmetic operators?     

a) Numeric         

b) Boolean         

c) Characters     

d) Numeric & Characters

 

  1. Modulus operator, %, can be applied to which of these?       

a) Integers         

b) Floating – point numbers       

c)  Integers and floating – point numbers            

d) point numbers

 

28.With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?              

  1. x++;                                                              
  2. x = x + 1;                                                      
  3. x += 1;                                                          
  4. x =+ 1;          

a) 1, 2 & 3           

b) 1 & 4

c) 1, 2, 3 & 4       

d) 3 & 2

                                               

  1. Decrement operator, −−, decreases the value of variable by what number?

a) 1        

b) 2       

c) 3        

d) 4

 

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

     class increment                                                           

     {                                                        

         public static void main(String args[])                                                              

         {                                                                    

              int g = 3;                                                

              System.out.print(++g * 8);                                                           

         }                                                    

     }        

a) 25     

b) 24     

c) 32      

d) 33

                                               

  1. Which of these is not a bitwise operator?     

a) &       

b) &=    

c) |=     

d) <=

 

  1. Which operator is used to invert all the digits in a binary representation of a number?            

a) ~       

b) <<<  

c) >>>  

d) ^

 

  1. On applying Left shift operator, <<, on integer bits are lost one they are shifted past which position bit?        

a) 1        

b) 32     

c) 33      

d) 31

 

  1. Which right shift operator preserves the sign of the value?  

a) <<     

b) >>    

c) <<=  

d) >>=

 

35.What is the output of relational operators?  

a) Integer           

b) Boolean         

c) Characters     

d) Double

 

  1. Which of these is returned by “greater than”, “less than” and “equal to” operators?

a) Integers         

b) Floating – point numbers       

c) Boolean         

d) Character

 

                                               

  1. Which of these operators can skip evaluating right hand operand?   

a) !        

b) |       

c) &       

d) &&

 

  1. Which of these statements is correct?           

a) true and false are numeric values 1 and 0       

b) true and false are numeric values 0 and 1       

c) true is any non zero value and false is 0            

d) true and false are non numeric values

 

39.Which of these have highest precedence?    

a) ()       

b) ++    

c) *        

d) >>

 

  1. What is the value stored in x in the following lines of Java code?        

   int x, y, z;                                                         

    x = 0;                                                

    y = 1;                                                

    x = y = z = 8;                   

a) 0        

b) 1       

c) 9        

d) 8

                                                                                               

  1. What is the value stored in x in the following lines of Java code?          

 int x, y, z;                                                           

    x = 0;                                                

    y = 1;                                                

    x = y = z = 8;                   

a) 0        

b) 1       

c) 9        

d) 8

42. Which of these keywords is used to define packages in Java?

a) pkg

b) Pkg

c) package

d) Package

 

  1. Which of these is a mechanism for naming and visibility control of a class and its content?

a) Object

b) Packages

c) Interfaces

d) None of the Mentioned.

 

  1. Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?

a) Public

b) Protected

c) Private

d) Friendly

 

  1. Which of the following is the correct way of importing an entire package ‘pkg’?

a) import pkg.

b) Import pkg.

c) import pkg.*

d) Import pkg.*

 

  1. Which of the following is an incorrect statement about packages?

a) Package defines a namespace in which classes are stored

b) A package can contain other package within it

c) Java uses file system directories to store packages

d) A package can be renamed without renaming the directory in which the classes are stored

 

 

  1. Which of these selection statements test only for equality?

a) if       

b) switch            

c) if & switch     

d) if-else

48. Which of these are selection statements in Java?     

a) if()    

b) for()

c) continue        

d) break

 

  1. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

a) do-while

b) while

c) for

d) for-each

 

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

a) break

b) return

c) exit

d) continue

 

  1. Which of this statement is incorrect?

a) switch statement is more efficient than a set of nested ifs

b) two case constants in the same switch can have identical values

c) switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression

d) it is possible to create a nested switch statements

 

  1. What is the output of Java program with IF statement?

if(1)

{

  System.out.println(“OK”);

}

A) OK

B) No output

C) Compiler error

D) Runtime error

 

 

 

  1. If the condition of an IF-statement is false, which is true below.

 

A) IF block is executed.

B) ELSE block is executed.

C) Both IF and ELSE blocks are skipped.

D) Both IF and ELSE blocks are executed.

 

 

  1. An ELSE statement must be preceded by ___ statement in Java.

A) IF

B) ELSE IF

C) IF or ELSE IF

D) IF ELSE

 

  1. An IF statement in Java is also a ___ statement.

A) boolean

B) conditional

C) iterative

D) optional

 

  1. An IF or ELSE IF statement accepts ___ as input before branching.

A) boolean

B) int

C) float

D) char

 

  1. Which of the following is not OOPS concept in Java?

a) Inheritance

b) Encapsulation

c) Polymorphism

d) Compilation

 

  1. Which of the following is a type of polymorphism in Java?

a) Compile time polymorphism

b) Execution time polymorphism

c) Multiple polymorphism

d) Multilevel polymorphism

 

  1. When does method overloading is determined?

a) At run time

b) At compile time

c) At coding time

d) At execution time

 

  1. Which of these keywords is used to make a class?

a) class

b) struct

c) int

d) none of the mentioned

 

  1. Which of the following is a valid declaration of an object of class Box?

a) Box obj = new Box();

b) Box obj = new Box;

c) obj = new Box();

d) new Box obj;

 

  1. Which of these operators is used to allocate memory for an object?

a) malloc

b) alloc

c) new

d) give

 

  1. What is the process of defining more than one method in a class differentiated by method signature?

a) Function overriding

b) Function overloading

c) Function doubling

d) None of the mentioned

 

  1. Which of the following is a method having same name as that of it’s class?

a) finalize

b) delete

c) class

d) constructor

 

  1. Which method can be defined only once in a program?

a) main method

b) finalize method

c) static method

d) private method

 

  1. Which of these class is superclass of String and StringBuffer class?

a) java.util

b) java.lang

c) java.sql

d) java.io

 

  1. Which of these operators can be used to concatenate two or more String objects?

a) +

b) +=

c) &

d) ||

 

  1. Which of this method of class String is used to obtain a length of String object?

a) get()

b) Sizeof()

c) lengthof()

d) length()

  1. Which of these method of class String is used to extract a single character from a String object?

a) CHARAT()

b) chatat()

c) charAt()

d) ChatAt()

 

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

a) String()

b) String(void)

c) String(0)

d) String

 

  1. Which of these is correct way of inheriting class A by class B?

a) class B + class A {}

b) class B inherits class A {}

c) class B extends A {}

d) class B extends class A {}

 

  1. What is not type of inheritance?

a) Single inheritance

b) Double inheritance

c) Hierarchical inheritance

d) Multiple inheritance

 

  1. Using which of the following, multiple inheritance in Java can be implemented?

a) Interfaces

b) Multithreading

c) Protected methods

d) Private methods

 

  1. All classes in Java are inherited from which class?

a) java.lang.class

b) java.class.inherited

c) java.class.object

d) java.lang.Object

 

  1. In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

a) Protected

b) Private

c) Public

d) Static

  1. From the following statements which is a disadvantage of an java array?

An array can hold primitive types data

An array has its size that is known as array length

An array knows only its type that it contains. Array type is checked at the compile-time

An array holds only one type of data

77.The following Syntax is used for?

 

class Subclass-name extends Superclass-name

{

//methods and fields

}

 

  1. Polymorphism
  2. Encapsulation
  3. Inheritance
  4. None of the above
  1. Which constructor creates an empty string buffer with the specified capacity as length.
  1. StringBuffer()
  2. StringBuffer(String str)
  3. StringBuffer(int capacity)
  4. None of the above
  1. If you are inserting any value in the wrong index as shown below,
  1. int a[]=new int[5];
  2. a[10]=50;

it would result in ______.

  1. NullPointerException
  2. ArrayIndexOutOfBoundsException
  3. ArithmeticException
  4. NumberFormatException
  1. The following program is an example of?

class Simple{

public static void main(String args[]){

String s=”sunita”;

System.out.println(s.length());//6

}

}

  1. length() method
  2. intern() method
  3. trim() method
  4. charAt() method

81.Breaking a string or stream into meaningful independent words is known as String Tokenization.

  1. True
  2. False
  1. Which variables are created when an object is created with the use of the keyword ‘new’ and destroyed when the object is destroyed?
  1. Local variables
  2. Instance variables
  3. Class Variables
  4. Static variables
  1. The Object class is not a parent class of all the classes in java by default.
  1. True
  2. False
  1. Which access specifiers can be used for a class so that it’s members can be accessed by a different class in the different package?
  1. Private
  2. Public
  3. Protected
  4. None of the above
  1. Which is a mechanism where one object acquires all the properties and behaviors of the parent object?
  1. Inheritance
  2. Encapsulation
  3. Polymorphism
  4. None of the above

86.Which is a technique in Java in which a class can have any number of constructors that differ in parameter lists?

  1. Constructor overloading
  2. Method overloading
  3. Operator overloading
  4. None of the above
  1. What output you will get if you run this program?

class Modulus {

public static void main(String args[]) {

int x = 42;

double y = 42.25;

System.out.println(“x mod 10 = ” + x % 10);

System.out.println(“y mod 10 = ” + y % 10);

}

}

  1. x mod 10 = 2

y mod 10 = 2.25

  1. x mod 10 = 4

y mod 10 = 2.50

  1. x mod 10 = 6

y mod 10 = 3.25

  1. x mod 10 = 2

y mod 10 = 4.25

  1. Multiple inheritances is not supported in case of class but it is supported in case of interface.
  1. True
  2. False
  1. By interface, we cannot support the functionality of multiple inheritances.
  1. True
  2. False
  1. What type of constructor is used to provide different values to the distinct objects?
  1. Default constructor
  2. Parameterized constructor
  3. Overloading constructor
  4. None of the above
  1. JVM stands for?
  1. Java Very Large Machine
  2. Java Verified Machine
  3. Java Very Small Machine
  4. Java Virtual Machine

92.Which keyword is used by classes to implement an interface?

  1. import
  2. implements
  3. instance of
  4. None of the above

93.Who is also called father of Java Programming Language?

  1. James Gosling
  2. Ken Thompson
  3. Dennis Richie
  4. None of the above
  1. What is the advantage of Method Overloading?
  1. Method overloading increases the readability of the program
  2. Method overloading does not increases the readability of the program
  3. Method overloading does not increases the reliability of the program
  4. None of the above
  1. Which type of inheritance one super-class have more than one sub-class?
  1. Hierarchical inheritance
  2. Single inheritance
  3. Multiple inheritances
  4. Multilevel inheritance
  1. If a subclass has the same method as declared in the parent class it is known as ______.
  1. Method overriding
  2. Method overloading
  3. Constructor overloading
  4. None of the above
  1. If there is no constructor in a class, compiler automatically creates a default constructor.
  1. True
  2. False
  1. Which is nothing but a blueprint or a template for creating different objects which defines its properties and behaviours?
  1. An Array
  2. A class
  3. Interface
  4. None of the above
  1. Which type of polymorphism is nothing but the method overloading in java?
  1. Compile time polymorphism
  2. Runtime polymorphism
  3. Static polymorphism
  4. Both A & C
  1. Which class cannot be instantiated?
  1. Abstract Class
  2. Static Class
  3. Both A & B
  4. None of the above
  1. Which method cannot be overridden?
  1. Final Method
  2. Final class
  3. Final Variable
  4. Both A & C
  1. Which is a perfect example of runtime polymorphism?
  1. Method overloading
  2. Method overriding
  3. Constructor overloading
  4. None of the above

 UNIT 2

  1. When does Exceptions in Java arises in code sequence?
  2. a) Run Time
  3. b) Compilation Time
  4. c) Can Occur Any Time
  5. d) None of the mentioned

 

  1. Which of these keywords is not a part of exception handling?
  2. a) try
  3. b) finally
  4. c) thrown
  5. d) catch

 

  1. Which of these keywords must be used to monitor for exceptions?
  2. a) try
  3. b) finally
  4. c) throw
  5. d) catch

 

  1. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
  2. a) try
  3. b) finally
  4. c) throw
  5. d) catch

 

  1. Which of these keywords is used to manually throw an exception?
  2. a) try
  3. b) finally
  4. c) throw
  5. d) catch

 

  1. What requires less resources?
  2. a) Thread
  3. b) Process
  4. c) Thread and Process
  5. d) Neither Thread nor Process

 

  1. What does not prevent JVM from terminating?
  2. a) Process
  3. b) Daemon Thread
  4. c) User Thread
  5. d) JVM Thread

 

  1. What decides thread priority?
  2. a) Process
  3. b) Process scheduler
  4. c) Thread
  5. d) Thread scheduler

 

  1. What is true about time slicing?
  2. a) Time slicing is OS service that allocates CPU time to available runnable thread
  3. b) Time slicing is the process to divide the available CPU time to available runnable thread
  4. c) Time slicing depends on its implementation in OS
  5. d) Time slicing allocates more resources to thread

 

  1. What should not be done to avoid deadlock?
  2. a) Avoid using multiple threads
  3. b) Avoid hold several locks at once
  4. c) Execute foreign code while holding a lock
  5. d) Use interruptible locks

 

  1. What is true about threading?
  2. a) run() method calls start() method and runs the code
  3. b) run() method creates new thread
  4. c) run() method can be called directly without start() method being called
  5. d) start() method creates new thread and calls code written in run() method

 

  1. Which of the following is a correct constructor for thread?
  2. a) Thread(Runnable a, String str)
  3. b) Thread(int priority)
  4. c) Thread(Runnable a, int priority)
  5. d) Thread(Runnable a, ThreadGroup t)

 

  1. Which of the following stops execution of a thread?
  2. a) Calling SetPriority() method on a Thread object
  3. b) Calling notify() method on an object
  4. c) Calling wait() method on an object
  5. d) Calling read() method on an InputStream object

 

  1. Which of the following will ensure the thread will be in running state?
  2. a) yield()
  3. b) notify()
  4. c) wait()
  5. d) Thread.killThread()

 

  1. Which of these stream contains the classes which can work on character stream?
  2. a) InputStream
  3. b) OutputStream
  4. c) Character Stream
  5. d) All of the mentioned

 

  1. Which of these class is used to read characters in a file?
  2. a) FileReader
  3. b) FileWriter
  4. c) FileInputStream
  5. d) InputStreamReader

 

  1. Which of these method of FileReader class is used to read characters from a file?
  2. a) read()
  3. b) scanf()
  4. c) get()
  5. d) getInteger()

 

  1. Which of these class can be used to implement the input stream that uses a character array as the source?
  2. a) BufferedReader
  3. b) FileReader
  4. c) CharArrayReader
  5. d) FileArrayReader

 

  1. Which of these classes can return more than one character to be returned to input stream?
  2. a) BufferedReader
  3. b) Bufferedwriter
  4. c) PushbachReader
  5. d) CharArrayReader

 

  1. Which of these package contains classes and interfaces for networking?
  2. a) java.io
  3. b) java.util
  4. c) java.net
  5. d) java.network

 

  1. Which of these is a protocol for breaking and sending packets to an address across a network?
  2. a) TCP/IP
  3. b) DNS
  4. c) Socket
  5. d) Proxy Server

 

  1. How many ports of TCP/IP are reserved for specific protocols?
  2. a) 10
  3. b) 1024
  4. c) 2048
  5. d) 512

 

  1. How many bits are in a single IP address?
  2. a) 8
  3. b) 16
  4. c) 32
  5. d) 64

 

  1. Which of these is a full form of DNS?
  2. a) Data Network Service
  3. b) Data Name Service
  4. c) Domain Network Service
  5. d) Domain Name Service

 

  1. Which of these class is used to encapsulate IP address and DNS?
  2. a) DatagramPacket
  3. b) URL
  4. c) InetAddress
  5. d) ContentHandler
  6. Unchecked exceptions are checked at compile-time rather they are checked at runtime.


  7. True
  8. False
  1. Which mechanism is used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed?
  1. Inter-thread communication
  2. Initial-thread communication
  3. Mutual Exclusive
  4. None of the above
  1. An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program’s instructions.
  1. True
  2. False
  1. Mutual exclusive and inter-thread communication are which type of Synchorization?
  1. Thread Synchronization
  2. Process Synchronization
  3. Object Synchronization
  4. None of the above
  1. Which is irrecoverable?
  1. Error
  2. Checked Exception
  3. Unchecked Exception
  4. Both B & C
  1. Which Exception occurs when a class is not found while dynamically loading a class using the class loaders?
  1. ClassNotFoundException
  2. ClassFoundException
  3. NoClassDefFoundError
  4. ClassDefFoundError

32.Classes in the same package cannot access each other’s package-access members.

  1. True
  2. False
  1. Which is used to separate the hierarchy of the class while declaring an import statement?
  1. Package
  2. Applet
  3. Browser
  4. All of the above

34.The following program is an example for?

class Student{

int id;

String name;

void display(){System.out.println(id+” “+name);}

public static void main(String args[]){

Student s1=new Student();

Student s2=new Student();

s1.display();

s2.display();

}

}

  1. Parameterized constructor
  2. Default Constructor
  3. Overloading Constructor
  4. None of the above
  1. These two ways

By extending Thread class

By implementing Runnable interface.

are used to?

  1. Joining a thread
  2. Naming a thread
  3. Create a thread
  4. sleeping a thread
  1. The following exceptions:

NullPointerException,

ArrayIndexOutOfBoundsException,

ArithmeticException,

NumberFormatException

are seen in _______

  1. Checked exception
  2. Unchecked exception
  3. Both A & B
  4. None of the above
  1. Exception Handling is a mechanism to handle runtime errors
  1. True
  2. False
  1. The life cycle of the thread is controlled by ?
  1. JVM
  2. JDK
  3. JRE
  4. None of the above

 UNIT 3

 

  1. Which of these packages contains all the classes and methods required for even handling in Java?
  2. a) java.applet
  3. b) java.awt
  4. c) java.event
  5. d) java.awt.event

 

  1. What is an event in delegation event model used by Java programming language?
  2. a) An event is an object that describes a state change in a source
  3. b) An event is an object that describes a state change in processing
  4. c) An event is an object that describes any change by the user and system
  5. d) An event is a class used for defining object, to create events

 

  1. Which of these methods are used to register a keyboard event listener?
  2. a) KeyListener()
  3. b) addKistener()
  4. c) addKeyListener()
  5. d) eventKeyboardListener()

 

  1. Which of these methods are used to register a mouse motion listener?
  2. a) addMouse()
  3. b) addMouseListener()
  4. c) addMouseMotionListner()
  5. d) eventMouseMotionListener()

 

  1. What is a listener in context to event handling?
  2. a) A listener is a variable that is notified when an event occurs
  3. b) A listener is a object that is notified when an event occurs
  4. c) A listener is a method that is notified when an event occurs
  5. d) None of the mentioned

 

  1. Event class is defined in which of these libraries?
  2. a) java.io
  3. b) java.lang
  4. c) java.net
  5. d) java.util

 

  1. Which of these methods can be used to determine the type of event?
  2. a) getID()
  3. b) getSource()
  4. c) getEvent()
  5. d) getEventObject()

 

  1. Which of these class is super class of all the events?
  2. a) EventObject
  3. b) EventClass
  4. c) ActionEvent
  5. d) ItemEvent

 

  1. Which of these events will be notified if scroll bar is manipulated?
  2. a) ActionEvent
  3. b) ComponentEvent
  4. c) AdjustmentEvent
  5. d) WindowEvent

 

  1. Which of these events will be generated if we close an applet’s window?
  2. a) ActionEvent
  3. b) ComponentEvent
  4. c) AdjustmentEvent
  5. d) WindowEvent

 

  1. Which of these packages contains all the event handling interfaces?
  2. a) java.lang
  3. b) java.awt
  4. c) java.awt.event
  5. d) java.event

 

  1. Which of these interfaces handles the event when a component is added to a container?
  2. a) ComponentListener
  3. b) ContainerListener
  4. c) FocusListener
  5. d) InputListener

 

  1. Which of these interfaces define a method actionPerformed()?
  2. a) ComponentListener
  3. b) ContainerListener
  4. c) ActionListener
  5. d) InputListener

 

  1. Which of these interfaces define four methods?
  2. a) ComponentListener
  3. b) ContainerListener
  4. c) ActionListener
  5. d) InputListener

 

  1. Which of these interfaces define a method itemStateChanged()?
  2. a) ComponentListener
  3. b) ContainerListener
  4. c) ActionListener
  5. d) ItemListener

 

  1. Which of these methods will be invoked if a character is entered?
  2. a) keyPressed()
  3. b) keyReleased()
  4. c) keyTyped()
  5. d) keyEntered()

 

  1. Which of these methods is defined in MouseMotionAdapter class?
  2. a) mouseDragged()
  3. b) mousePressed()
  4. c) mouseReleased()
  5. d) mouseClicked()

 

  1. Which of these is a superclass of all Adapter classes?
  2. a) Applet
  3. b) ComponentEvent
  4. c) Event
  5. d) InputEvent

 

  1. Which of the following class is derived from the container class?
  2. a) Component                   
  3. b) Panel
  4. c) MenuComponent               
  5. d) List

 

 21.Name of the class used to represent a GUI application window, which is optionally resizable and can have a title bar, an icon, and menus.

  a)Window                          

b)Panel

 c)Dialog                        

 d)Frame

 

22.Which abstract class is the super class of all menu related classes?

  1. a) MenuComponent        

  b )MenuBar

  c )MenuItem             

  1. d) CheckboxMenuItem

 

  1. Which of the following is the default Layout Manager ?
  2. a) FlowLayout
  3. b) BorderLayout

c)GridLayout

d)CardLayout

 

  1. How do you change the current layout manager for container?
  2. use setLayout() 
  3. once created you cannot change it 
  4. You set setLayoutManager() 
  5. use updateLayout() 

 

  1. AWT components are
  2. A) lightweight
  3. B) heavyweight
  4. C) equalweight
  5. D) weightless

 

  1. Which of these packages contain all the collection classes?
  2. a) java.lang
  3. b) java.util
  4. c) java.net
  5. d) java.awt

 

  1. Which of these classes is not part of Java’s collection framework?
  2. a) Maps
  3. b) Array
  4. c) Stack
  5. d) Queue

 

  1. Which of this interface is not a part of Java’s collection framework?
  2. a) List
  3. b) Set
  4. c) SortedMap
  5. d) SortedList

 

  1. Which of these methods deletes all the elements from invoking collection?
  2. a) clear()
  3. b) reset()
  4. c) delete()
  5. d) refresh()

 

  1. What is Collection in Java?
  2. a) A group of objects
  3. b) A group of classes
  4. c) A group of interfaces
  5. d) A group of array

 

  1. Which is used for reading streams of raw bytes such as image data and for reading streams of characters, consider using FileReader?

  2. FileInputStream
  3. FileOutputStream
  4. Both A & B
  5. None of the above
  6. Which package is used for GUI?

 

  1. java.lang
  2. java.awt
  3. java.lang.ref
  4. java.io