Topic: OOP Concepts
1. What is the difference between procedural programming and object-oriented
programming?
2. What is encapsulation in OOP? Provide an example.
3. What are the main features of OOP?
4. What is inheritance in OOP? Provide an example.
5. What are classes and objects in OOP? Provide an example.
6. What is polymorphism in OOP? Provide an example.
7. What is the difference between static and dynamic polymorphism? Provide examples.
8. What are the comparisons between method overloading and method overriding?
9. What is method overloading? Provide a sample program.
10. What is the difference between Object-Oriented Programming (OOP) and
conventional programming paradigms?
11. What are the advantages and disadvantages of Object-Oriented Programming (OOP)
compared to other programming paradigms?
12. What is the difference between a class and an object in OOP? Explain their respective
roles.
13. What is message passing in OOP? Discuss its role in object interaction.
14. What is inheritance in OOP? Discuss its advantages and use cases.
15. What is the difference between encapsulation and abstraction in OOP?
16. What is the difference between polymorphism and method overloading in OOP?
17. What are the different types of polymorphism? Provide examples.
18. What is the difference between ‘==’ and equals() in Java?
19. What is data encapsulation in Java?
Topic: Java Basics
1. What are classes and objects in Java? Provide examples.
2. What is the difference between a class and a structure in Java?
3. What are break and continue statements in Java?
4. What are the types of variables in Java? Provide examples in object-oriented
programming.
5. What are the various types of constructors in object-oriented programming? Is it
always necessary to create objects from a class?
6. What are the control statements used in Java? Describe their syntax with suitable
illustrations.
7. What are the different kinds of wrapper classes in Java?
8. What is bytecode in Java?
9. What are the differences between method overloading and method overriding in Java?
10. What are the different uses of the "this" keyword in Java? Provide examples.
11. Why is Java called a platform-independent language? Describe your answer.
12. What are objects and classes in Java?
13. What is the "this" keyword in Java?
14. What is instance variable hiding in Java?
15. How can static polymorphism be achieved in Java?
16. What is compile-time polymorphism and how is it different from runtime
polymorphism in Java?
17. What are the different access specifiers in Java? Provide examples.
18. What is the use of the finalize() method in Java?
19. What is the role of constructor overloading in Java? Provide an example.
20. What are the methods of the String class in Java?
21. What is a constructor in Java? Provide an example.
Topic: Java Features
1. Why is Java called a platform-independent language?
2. What are JVM, JRE, and JDK in Java?
Topic: Java GUI Programming
1. What is the difference between a Frame and a Panel in AWT?
2. What is the purpose of a layout manager in AWT programming?
3. What is AWT in Java programming, and how does it differ from Swing?
4. What is the role of layout managers in Java GUI programming? Provide examples of
different layout managers.
5. How does event handling work in Java GUI programming? What is the role of
listeners?
6. What is the significance of JButton and JFrame in Swing programming? Provide
examples.
7. What are layout managers in Java AWT programming? Analyze at least three
different layout managers.
8. How does the event handling mechanism work in Java AWT programming? Explain
how events are generated, propagated, and handled in AWT.
9. What is the difference between AWT and Swing in Java GUI programming? Classify
the advantages and disadvantages of each.
10. What is event delegation in Java AWT programming?
11. How can an example of creating a custom button component be explained?
12. What is the role of the EventQueue in Java AWT programming? Illustrate how events
are managed and dispatched in AWT applications.
13. What is the concept of threading in Java AWT programming?
14. How can an example of a simple Swing program that includes a JFrame, JButton, and
an event handler be developed?
15. What are the key concepts and components of AWT (Abstract Window Toolkit) in
Java programming? How does AWT contribute to the creation of graphical user
interfaces (GUIs)?
16. What is the role and functionality of a JButton in Java Swing? Provide an example
code snippet to demonstrate its usage and customization.
17. What is the role and functionality of a JButton in Java Swing? Provide an example
code snippet to demonstrate its usage and customization.
18. What is the purpose of a JFrame in Java Swing? Provide a comprehensive explanation
of its key features and the steps involved in creating a basic JFrame application.
19. What is the role of layout and component managers in Java GUI programming?
Provide examples of commonly used layout managers and describe their
characteristics.
20. What is the concept of event handling in Java GUI programming? Discuss the event
model and provide examples of handling events in Swing applications.
21. How can the use of layout managers in Swing be explained by creating a program
with multiple components and applying different layout managers? Explain how each
layout manager affects the arrangement of components.
22. How can the creation of a simple Swing application with multiple components,
including buttons, labels, and text fields, be evaluated? Implement event handling to
enhance interactivity.
Topic: Java Packages and Access Specifiers
1. What are the advantages of packages in Java?
2. How can a package be accessed from another package in Java?
3. What is a package in OOP?
4. How do packages work in Java?
5. What is a subpackage in Java?
6. What is the concept of package creation in Java? Discuss its role in organizing and
managing classes and interfaces.
7. What are the advantages of using packages in Java development, particularly in terms
of code organization, reusability, and namespace management?
8. How does Java support member access control for packages? What are the different
access modifiers available for package members?
9. What is the process of importing packages in Java? Discuss the various methods of
accessing members within imported packages.
10. What is a user-defined package in Java? Provide an example.
11. What are some built-in packages in Java?
12. How can a package be applied by importing its fully qualified name?
Topic: Java Multithreading
1. What is a thread in Java?
2. What is the Thread class in Java?
3. What is multithreading in Java?
4. What are the advantages of multithreading in Java?
5. What are the basics of multithreading in Java?
6. What is the thread lifecycle in Java?
7. What are deadlocks for threads in Java? How do they occur?
8. How can multiple threads be created in a multithreaded application in Java? What are
the common methods and considerations in their creation?
9. What is the life cycle of a thread in Java?
10. How can a thread example be evaluated by using the Runnable interface in Java?
11. What is the difference between a thread and a process in Java?
12. What is the multitasking concept in threads in Java?
Topic: Exception Handling
1. How does exception handling work in Java?
2. What is exception handling in Java?
3. What are the different types of exception classes in Java?
4. How are different types of exception classes used in exception handling in Java?
Topic: Miscellaneous
1. What are the different ways by which String, class, and object can be created in Java?
2. What is the role of an abstract class in Java?
3. What is the order of calling constructors in multi-level inheritance in Java?
4. What is the difference between static loading and dynamic class loading in Java?
5. How can the process of creating and implementing interfaces in Java be explained?
Highlight their role in achieving multiple inheritance.
6. What is the significance of the "super" keyword in Java inheritance? How is it used to
call a superclass constructor?
7. What is the concept of a multilevel hierarchy in inheritance in Java? Provide an
example demonstrating its use.
8. What is the "final" keyword in Java, particularly in the context of inheritance and
method overriding?
9. How are abstract classes and methods utilized in Java? What purpose do they serve in
object-oriented programming?
10. What is the significance of the constructor chaining process in Java inheritance? How
does it ensure proper initialization of objects?
Topic: Java Basics
1. What is Byte code defined as in Java?
o Platform dependent
o Platform independent
o Architecture dependent
o Depend on OS
2. What is not a concept of OOP in Java?
o Encapsulation
o Inheritance
o Polymorphism
o Compilation
3. Which of the following is not an iterative statement in Java?
o for(;;)
o while()
o do-while
o if-else
4. What is the full form of JVM?
o Java Virtual Machine
o Java Virtual Methods
o Java Versatile Machine
o None of these
5. What is the full form of JIT?
o Java In Time
o Java In Technique
o Just In Time
o Just In Technique
6. What are Java source codes converted into?
o Byte code
o Machine code
o Bit code
o None of these
7. Which statement is true for Java?
o Platform independent
o Platform dependent
o Code dependent
o Sequence dependent
8. What is the extension of Java code files?
o .class
o .java
o .txt
o .js
9. What does a Boolean variable contain in Java?
o True & False
o 1&2
o Any integer value
o 1
10. What was Java language initially called?
o Sumata
o J++
o OAK
o Pine
11. Who is known as the father of Java Programming Language?
o James Gosling
o M. P Java
o Charel Babbage
o Blais Pascal
12. What is byte code in Java?
o Code generated by a Java compiler
o Code generated by a Java Virtual Machine
o Name of Java source code file
o Block of code written inside a class
13. Which of the following is not a Java keyword?
o double
o switch
o then
o none
14. Which of the following is not a Java feature?
o Dynamic
o Architecture Neutral
o Use of pointers
o Object-oriented
15. What is used to find and fix bugs in Java programs?
o JVM
o JRE
o JDB
o JDK
16. Who invented Java Programming?
o Guido van Rossum
o James Gosling
o Dennis Ritchie
o Bjarne Stroustrup
17. Which statement is true about Java?
o Java is a sequence-dependent programming language
o Java is a code-dependent programming language
o Java is a platform-dependent programming language
o Java is a platform-independent programming language
18. Which component is used to compile, debug, and execute Java programs?
o JRE
o JIT
o JDK
o JVM
19. What is the extension of compiled Java classes?
o .txt
o .js
o .java
o .class
20. Which environment variable is used to set the Java path?
o MAVEN_Path
o JavaPATH
o JAVA
o JAVA_HOME
21. Which component is responsible for converting bytecode into machine-specific code in Java?
o JVM
o JDK
o JIT
o JRE
22. Which component is responsible for running a Java program?
o JVM
o JDK
o JIT
o JRE
23. What is the use of an interpreter in Java?
o They read high-level code and execute them
o They convert bytecode to machine language code
o They are intermediated between JIT and JVM
o It is a synonym for JIT
Topic: Object-Oriented Programming (OOP) Concepts
24. Which process is a compile-time polymorphism in Java?
o Encapsulation
o Method overriding
o Method overloading
o Abstraction
25. Which of the following is used as a code reusability feature in Java?
o Polymorphism
o Inheritance
o Abstraction
o Encapsulation
26. What are the features of OOP in Java?
o Encapsulation
o Inheritance
o Polymorphism
o All of these
27. What is method overloading defined as in Java?
o run time
o compile time
o coding time
o execution time
28. What are the two types of polymorphism in Java? (Select one)
o Compile time polymorphism
o Execution time polymorphism
o Multiple polymorphism
o Multilevel polymorphism
29. What is the process through which one can control parts of a program to access the
members of a class in Java?
o Polymorphism
o Encapsulation
o Abstraction
o Recursion
30. Which feature cannot be implemented if we do not use classes in a program?
o Inheritance
o Encapsulation
o Object
o Static polymorphism
31. What is it called when different properties and functions of a real-world entity are grouped
into a single entity?
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
32. Which of the following best describes encapsulation in Java?
o It is a way of combining various data members into a single unit
o It is a way of combining various member functions into a single unit
o It is a way of combining various data members and member functions into a single
unit which can operate on any data
o It is a way of combining various data members and member functions that operate
on those data members into a single unit
33. Which feature allows one object to interact with another object in Java?
o Data transfer
o Data binding
o Message passing
o Message reading
34. What is the feature called when the same message is passed to objects of several different
classes, and all of those can respond differently?
o Inheritance
o Polymorphism
o Overloading
o Overriding
35. What is the programming style of the object-oriented conceptual model?
o Invariant relationships
o Algorithms
o Goals, often expressed in a predicate calculus
o Classes and objects
36. What is the concept in type theory where a single name can represent objects from multiple
classes that share a common superclass?
o Monomorphism
o Type Checking
o Polymorphism
o Generalization
37. What type of hierarchy is inheritance an example of?
o Class Structure
o Object Structure
o Class structure and Object Structure
o None of the mentioned
38. Which property is associated with objects in Java?
o State
o Behavior
o Identity
o All of the mentioned
39. What is the correct term for the following code: class PersonnelRecord { char name[100]; int
socialSecurityNumber; char department[10]; float salary; }?
o Objects
o Class
o Objects and Class
o None of the mentioned
40. Which is not an OOP concept in Java?
o Inheritance
o Encapsulation
o Polymorphism
o Compilation
41. Which concept of Java is a way of converting real-world objects in terms of class?
o Polymorphism
o Encapsulation
o Abstraction
o Inheritance
42. Which of the following is a type of polymorphism in Java?
o Multiple polymorphism
o Compile time polymorphism
o Multilevel polymorphism
o Execution time polymorphism
43. Which of these is supported by method overriding in Java?
o Abstraction
o Encapsulation
o Polymorphism
o None of these
44. Which is not a feature of Object-Oriented Programming?
o Class
o Method overloading
o Structure
o Object
Topic: Classes and Objects
45. Which is not a type of class in Java?
o final Class
o start Class
o abstract Class
o string Class
46. What is the valid declaration of an object of class Test in Java?
o Test obj = new Test();
o Test obj = new Test;
o obj = new Test();
o new Test obj;
47. Which operator is used to allocate memory for an object in Java?
o malloc
o alloc
o new
o free
48. Which method can be defined only once in a Java program?
o main method
o static method
o finalize method
o private method
49. What is a method that initializes an object immediately upon creation and has the same
name as the class?
o finalize
o class
o delete
o constructor
50. Which class can be openly accessed by others in Java?
o protected
o public
o private
o default
51. Which operator is used in Java runtime implementations to free the memory of an object?
o delete
o new
o free
o None of these
52. What is the return type of constructors in Java?
o int
o float
o does not return anything
o void
53. Which method is used to delete an object in Java?
o finalize()
o main()
o delete()
o None of these
54. Which class holds a collection of static methods and variables in Java?
o Void
o Runtime
o Process
o System
55. Which is a contiguous group of the same or related data items with a common name in
Java?
o Variable
o Constant
o Array
o None of these
56. What is it called when two methods have the same name but different parameters in Java?
o Method overriding
o Method overloading
o Operator overloading
o None of these
57. Which constructors can take arguments in Java?
o Default Constructor
o Copy Constructor
o Parameterized Constructor
o Dynamic Constructor
58. What is true about constructors in Java?
o A constructor must have the same name as the class it is declared within
o A constructor is used to create objects
o A constructor may be declared private
o All of the above
59. Which operator is used to allocate memory to an array variable in Java?
o alloc
o malloc
o calloc
o new
60. Which method must be made static in Java?
o main()
o delete()
o run()
o finalize()
61. What is the superclass of every class in Java?
o String class
o Object class
o ArrayList class
o Abstract class
62. Which method of the Object class can clone an object in Java?
o Objectcopy()
o copy()
o Object clone()
o clone()
63. Which method of the Object class is used to obtain the class of an object at runtime?
o get()
o void getclass()
o Class getclass()
o None of the mentioned
64. What is the class that prevents inheritance of a class in Java?
o super
o constant
o class
o final
65. Which of these keywords cannot be used for a class that has been declared final in Java?
o abstract
o extends
o none of the mentioned
o abstract and extends
66. Which class relies upon its subclasses for complete implementation of its methods in Java?
o Object class
o abstract class
o ArrayList class
o None of the mentioned
67. How are arrays implemented in Java?
o class
o object
o variable
o none of these
68. Which is the superclass of every class in Java?
o ArrayList
o Abstract class
o Object class
o String
69. What is the correct way of inheriting class A by class B in Java?
o class B + class A {}
o class B inherits class A {}
o class B extends A {}
o class B extends class A {}
70. Which of the following is correct to create an object of a class in Java?
o Creating reference only
o Only instantiating
o Creating reference and instantiating
o None of these
71. What is true about nested classes in Java?
o inner class and outer class both cannot access their properties
o inner class and outer class both can access their properties
o outer class can access inner class properties
o inner class can access outer class properties
Topic: Methods and Constructors
72. Which return type of a method does not return any value in Java?
o int
o void
o float
o double
73. Which keyword can be used to refer to the current class instance variable in Java?
o import
o abstract
o catch
o this
74. Which method of class StringBuffer is used to concatenate the string representation to the
end of a string in Java?
o concatenate()
o concat()
o append()
o join()
75. Which method of class String is used to remove leading and trailing whitespaces?
o trim()
o doTrim()
o replace()
o startsWith()
76. Which method of class String is used to extract a substring from a String object?
o substring()
o stringSub()
o String()
o None of these
77. Which method of class String is used to check whether a given object starts with a particular
string literal?
o startsWith()
o Starts()
o endsWith()
o ends()
78. Which methods are used to write into a file in Java?
o put()
o write()
o putFile()
o writeFile()
79. Which method returns the total number of bytes of memory available to the program in
Java?
o getMemory()
o TotalMemory()
o getProcessMemory()
o SystemMemory()
80. Which method of the String class is used to obtain a character at a specified index?
o CharacAt()
o characterAt()
o char()
o charAt()
81. Which method of the String class can be used to test two strings for equality?
o isqual()
o isequals()
o equal()
o equals()
82. Which of these methods can be used for writing console output in Java?
o print()
o write()
o println()
o All of these
83. How many arguments can be passed to the main() method in Java?
o One
o many
o two
o three
84. Which method of class String is used to compare two String objects for their equality?
o equals
o equal
o isequal
o isequals
85. Which method is used to compare a specific region inside a string with another specific
region in another string?
o regionMatch()
o match()
o RegionMatches()
o regionMatches()
86. What is the data type value returned by the equals() method of the String class in Java?
o char
o int
o boolean
o all of the mentioned
87. When is method overloading determined in Java?
o At run time
o At compile time
o At coding time
o At execution time
88. What in Java "System.out.print" is defined as?
o Method
o Object
o Class
o None of these
89. Which option is incorrect for constructors in Java?
o Constructor has the same name as the class name
o Constructor should have a return type
o A class can contain more than one constructor
o Constructor is automatically invoked whenever an object of the class is created
90. Why should the main method be static in Java?
o It can be accessed easily by the class loader
o It can be accessed by every method
o It can be executed without creating any instance of the class
o All of these
91. What is the correct way of calling a constructor having no parameters of superclass A by
subclass B in Java?
o super(void);
o superclass.();
o super.A();
o super();
Topic: Access Modifiers and Keywords
92. Which keyword is used to avoid modification of a variable in Java?
o final
o constant
o last
o static
93. How should all variables of a class be ideally described in Java?
o private
o protected
o public
o default
94. How can a protected modifier be accessed in Java?
o accessible only within the class
o accessible only within the package
o accessible by all
o All of these
95. When is the constructor of a class made private in Java?
o Any class can instantiate objects of class A
o Objects of class A can be instantiated only within the class where it is declared
o Inherited class can instantiate objects of class A
o Classes within the same package as class A can instantiate objects of class A
96. Which keyword does not permit overriding in the subclass in Java?
o public
o abstract
o final
o static
97. For which access specifier is the concept of a constructor applicable in Java?
o private
o public
o protected
o All of these
98. Which specifier is used to stop a method from being accessed by other classes in Java?
o default
o private
o protected
o public
99. Which of the following is not a Java modifier?
o public
o private
o friendly
o none
100. Which keyword is used to prevent the content of a variable from being modified in
Java?
final
constant
last
static
101. Which of these keywords can be used to prevent method overriding in Java?
static
constant
final
protected
102. What is the use of the final keyword in Java?
When a class is made final, a subclass of it cannot be created
When a method is final, it cannot be overridden
When a variable is final, it can be assigned a value only once
All of these
103. Which statement is false about the final keyword in Java?
A final method cannot be overridden in its subclasses
A final class cannot be extended
A final class cannot extend other classes
A final method can be inherited
104. Which keyword is used to define interfaces in Java?
Intf
intf
interface
int
105. Which one of the following is not an access modifier in Java?
Protected
Void
Public
Private
106. Which of the below is an invalid identifier with the main method in Java?
public
private
static
final
Topic: Data Types and Operators
107. What is the return type of the Math.random() method in Java?
Integer
String
Double
Boolean
108. What is a necessary condition for automatic type conversion in Java?
The destination type is smaller than the source type
The destination type is larger than the source type
The destination type can be larger or smaller than the source type
None of these
109. Which is a valid declaration of a boolean in Java?
boolean b1 = 1;
boolean b2 = false();
boolean b2 = false;
boolean b1 = 0;
110. What is the output of relational operators in Java?
Integer
Character
Boolean
None of these
111. What is the return type of the Greater Than, Less Than, and Equal To (Relational)
operators in Java?
Float
Integer
Boolean
Double
112. Which is the smallest data type in Java?
int
byte
short
long
113. In Java, array elements are stored in what type of memory locations?
Random
Sequential
Binary search
Sequential & Random
114. To what can the modulus operator (%) be applied in Java?
Both Integers and floating-point numbers
Integers
Floating-point numbers
None of the mentioned
115. Which of the following cannot be used as a variable name in Java?
identifier
keyword
identifier & keyword
none of the mentioned
116. What is a necessary condition for automatic type conversion in Java?
The destination type is smaller than the source type
The destination type is larger than the source type
The destination type can be larger or smaller than the source type
None of the mentioned
117. What is truncation in Java?
Floating-point value assigned to a floating type
Floating-point value assigned to an integer type
Integer value assigned to floating type
None of these
118. What is the numerical range of a char data type in Java?
0 to 256
-128 to 127
0 to 65535
0 to 32767
119. Which of these statements is false?
Equal to operator has least precedence
Brackets () have highest precedence
Subtraction operator has higher precedence than multiplication operator
Addition operator and subtraction operator have equal precedence
Topic: Strings
120. What is the name used for string operations in Java?
final class
start class
abstract class
string class
121. What is true about args in the following line of code: public static void main(String
args[])?
args is a String
args is an array of String
args is a Character
args is an array of Character
122. What is used to store command-line arguments in Java?
Integer
String array
Stack
int array
123. Which statement is incorrect about strings in Java?
String is a class
Every string is an object of class String
Strings in Java are mutable
Java defines a peer class of String called StringBuffer, which allows strings to be altered
124. Which statement is incorrect about strings in Java?
String is a class
Every string is an object of class String
Strings in Java are mutable
Java defines a peer class of String called StringBuffer, which allows strings to be altered
Topic: Control Statements
125. Which jump statement can skip processing the remainder of the code in its body for
a particular iteration in Java?
break
return
exit
continue
126. Which is true about the break statement in Java?
Break stops the execution of the entire program
Break halts the execution and forces the control out of the loop
Break forces the control out for a specific iteration and starts the execution of the next
iteration
Break halts the execution of the loop for a certain time frame
127. Which option transfers execution to different parts of your code based on the value
of an expression in Java?
if
switch
nested if-else
if-else
128. Which of these are selection statements in Java?
break
continue
for()
if()
Topic: Exception Handling
129. When do exceptions in Java arise in code sequence?
Run Time
Compilation Time
Can Occur Any Time
None of the mentioned
130. Which keyword is not a part of exception handling in Java?
try
thrown
catch
finally
131. Which keyword must be used to monitor for exceptions in Java?
try
finally
throw
catch
132. Which keyword must be used to handle the exception thrown by the try block in
some rational manner in Java?
try
finally
throw
catch
133. Which keyword is used to throw an exception manually in Java?
try
finally
throw
catch
134. Which exception is thrown when dividing by zero in Java?
NumberFormatException
ArithmeticException
NullPointerException
None of these
135. Which keyword is used to explicitly throw an exception in Java?
throw
try
catch
None of these
136. Which is the superclass of all exceptional type classes in Java?
RuntimeExceptions
String
Throwable
Cacheable
137. Which keyword is used for the block to be examined for exceptions in Java?
check
throw
catch
try
Topic: Multithreading
138. What is multithreaded programming in Java?
It’s a process in which two different processes run simultaneously
It’s a process in which two or more parts of the same process run simultaneously
It’s a process in which many different processes are able to access the same information
It’s a process in which a single process can access information from many sources
139. What are the types of multitasking in Java?
Process based
Thread based
Process and Thread based
None of the mentioned
140. What is thread priority defined as in Java?
Integer
Float
Double
Character
141. Which of the following statements is incorrect about threads in Java?
By multithreading, CPU idle time is minimized, and we can take maximum use of it
By multitasking, CPU idle time is minimized, and we can take maximum use of it
Two threads in Java can have the same priority
A thread can exist only in two states, running and blocked
142. Which of the following is not a method of the Thread class in Java?
yield()
sleep()
go()
stop()
143. How can a thread be created in Java?
Extending the Thread class
Implementing the Runnable interface
Both of the options are correct
None of these
144. Which method is called internally by the Thread start() method in Java?
execute()
run()
launch()
main()
145. When a class extends the Thread class, which method should it override to start that
thread?
join()
start()
run()
go()
146. Which statement is incorrect about threads in Java?
start() method is used to begin execution of the thread
run() method is used to begin execution of a thread before start() method in special cases
A thread can be formed by implementing the Runnable interface only
A thread can be formed by a class that extends the Thread class
Topic: Java Packages and Libraries
147. Which package contains classes and interfaces used for input and output operations
in Java?
java.net
java.io
java.lang
All of these
148. Which package contains all the built-in exceptions in Java?
java.io
java.lang
java.util
java.net
149. Which package contains the Random class in Java?
java.util package
java.lang package
java.awt package
java.io package
Topic: Static Members
150. Which of the following cannot be declared as static in Java?
Class
Variable
Method
Object
151. Which of the following cannot be declared static in Java?
Class
Variable
Method
Object
152. Which statement is incorrect about static methods in Java?
static methods can call other static methods only
static methods must only access static data
static methods cannot refer to this or super in any way
when an object of a class is declared, each object contains its own copy of static variables
Topic: Java Code Output
153. What is the output of the following Java code?
java
Copy
class output {
public static void main(String args[]) {
String s1 = "Hello i love java";
String s2 = new String(s1);
System.out.println((s1 == s2) + " " + s1.equals(s2));
true true
false false
true false
false true
154. What is the correct output of the following Java code?
java
Copy
class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
Thread[5,main]
Thread[main,0]
Thread[main,5]
Thread[main,5,main]
155. What is the priority of the thread in the following Java program?
java
Copy
class multithreaded_programing {
public static void main(String args[]) {
Thread t = Thread.currentThread();
System.out.println(t);
4
5
0
1
Topic: Java AWT and Swing
156. What does AWT stand for in Java?
Abstract Window Toolkit
All Writing ToolKit
Abstract Window Tool
Abstract Writing Toolkit
157. Which option leads to the portability and security of Java?
Bytecode is executed by JVM
The applet makes the Java code secure and portable
Use of exception handling
Dynamic binding between objects
158. Which class represents a window for a graphical application in Java AWT?
Frame
Panel
Window
Applet
159. What is the superclass of all AWT components?
Component
Widget
Container
Control
160. Which layout manager is suitable for arranging components in a grid-like structure in
Java?
BorderLayout
FlowLayout
GridLayout
CardLayout
161. Which event listener interface is used to handle mouse events in Java AWT?
ActionListener
MouseMotionListener
MouseListener
KeyListener
162. Which class provides support for drawing shapes and images on the screen in Java
AWT?
Graphics2D
Canvas
Image
Shape
163. Which method is used to set the font for a component in Java AWT?
setFont()
setStyle()
setFontStyle()
setComponentFont()
164. Which layout manager is used to arrange components in a horizontal or vertical row
in Java?
BorderLayout
FlowLayout
GridLayout
BoxLayout
165. What is the purpose of the repaint() method in Java AWT?
To update the component's visibility
To refresh the component's appearance
To resize the component
To remove the component from the screen
166. Which class is the superclass for all AWT event classes in Java?
EventObject
Event
AWTEvent
ComponentEvent
167. What does AWT stand for in Java programming?
Advanced Web Technologies
Abstract Window Toolkit
Application Window Toolkit
All Window Types
168. Which layout manager is typically used to arrange components in a grid format in
Java?
FlowLayout
BorderLayout
GridLayout
CardLayout
169. What is an event in Java GUI programming?
A graphical component
A user action or occurrence
A layout manager
A container class
170. Which Swing component is used to create a clickable button in a GUI?
JLabel
JButton
JTextField
JCheckBox
171. What is the main container class used to create a top-level window in a Swing
application?
JFrame
JPanel
JWindow
JDialog
172. Which function is called to display the output of an applet in Java?
display()
paint()
displayApplet()
PrintApplet()
Topic: Miscellaneous
173. Which option is used by the operating system to manage recursion in Java?
Tree
Array
Queue
Stack
174. Which of the following is false?
It is necessary to use the new operator to initialize an array
Array can be initialized using comma-separated expressions surrounded by curly braces
Array can be initialized when they are declared
None of these
175. What is not a use of the "this" keyword in Java?
Referring to the instance variable when a local variable has the same name
Passing itself to the method of the same class
Passing itself to another method
Calling another constructor in constructor chaining
176. In Java code, the line that begins with /* and ends with */ is known as what?
Multiline comment
Single line comment
Both A & B
None of these