
Q31
Q31 In Java, how is a 'static' variable different from an 'instance' variable?
Static variables are shared across all instances of a class
Static variables are reinitialized with each object instance
Instance variables are shared across all instances of a class
Instance variables are constants
Q32
Q32 What is polymorphism in Java?
The ability of a variable to hold different data types
The ability of a class to implement multiple methods with the same name
The ability of a method to perform different tasks based on the context
The ability of a class to extend multiple classes
Q33
Q33 What distinguishes an abstract class from a regular class in Java?
An abstract class cannot create objects
An abstract class only contains abstract methods
An abstract class cannot contain constructors
An abstract class cannot have instance variables
Q34
Q34 What will the following code output:
class Test {
static int x = 10;
} public class Main {
public static void main(String[] args) {
Test t1 = new Test(); System.out.println(t1.x); } }
10
0
Error
Null
Q35
Q35 Determine the output of this pseudocode:
CLASS Animal METHOD sound PRINT "Generic Sound" END CLASS Dog EXTENDS Animal METHOD sound PRINT "Bark" END CLASS Main CREATE Dog d CALL d.sound
Generic Sound
Bark
Error
None
Q36
Q36 What will be the result of this pseudocode?
CLASS Book VARIABLE title = "Java Programming" METHOD getTitle PRINT title END CLASS Main CREATE Book b CALL b.getTitle
Java Programming
null
Error
Title
Q37
Q37 Analyze this pseudocode:
CLASS Shape METHOD area RETURN 0 END CLASS Circle EXTENDS Shape VARIABLE radius = 5 METHOD area RETURN 3.14 * radius * radius END CLASS Main CREATE Circle c PRINT c.area
0
78.5
Error
None
Q38
Q38 Identify the issue in this code snippet:
class Book {
private String title; void setTitle(String title) {
title = title; }
}
The method does not set the instance variable
No issue
Syntax error
Logic error
Q39
Q39 Find the error in this Java code:
class Animal {
Animal() {
System.out.println("An animal is created");
}
} class Dog extends Animal {
Dog() { super();
System.out.println("A dog is created");
}
} public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
}
}
Incorrect use of super()
No error
Constructor not called
Syntax error
Q40
Q40 How does StringBuilder differ from StringBuffer in Java?
StringBuilder is synchronized; StringBuffer is not
StringBuilder is faster as it is not synchronized
StringBuilder and StringBuffer have different methods
StringBuilder allows storing strings of variable length
Q41
Q41 In Java, what is an interface?
A fully abstract class
A regular class
A concrete class
A template class
Q42
Q42 Can an interface in Java contain default methods?
Yes, from Java 8 onwards
No, interfaces cannot have default methods
Only in abstract classes
Only static methods are allowed
Q43
Q43 Can an interface in Java extend multiple interfaces?
Yes
No
Only if they are marker interfaces
Only abstract classes can extend multiple interfaces
Q44
Q44 Analyze the output of this code snippet:
interface A {
int val = 5;
}
interface B extends A {
int val = 10;
}
class Test implements B {
void display() {
System.out.println(val);
}
} public class Main {
public static void main(String[] args) {
Test t = new Test();
t.display();
}
}
5
10
Error
None
Q45
Q45 What does the 'import' statement do in a Java program?
It includes native libraries
It enhances performance
It allows access to classes in packages
It compiles the Java code
Q46
Q46 What is the significance of the CLASSPATH environment variable in Java?
It specifies the installation directory of Java
It sets the maximum memory allocation for the Java Virtual Machine
It tells the JVM where to look for user-defined classes and packages
It configures the security settings of the JVM
Q47
Q47 What is an exception in Java?
An error during program execution
A type of Java class
A method declaration
A user input error
Q48
Q48 What happens if an exception is thrown in a try block and is not caught in the corresponding catch block?
The exception is ignored
The program terminates
The exception is handled by the default handler
The program continues execution
Q49
Q49 What is the difference between checked and unchecked exceptions in Java?
Checked exceptions are detected at compile-time, unchecked at runtime
Checked exceptions are fatal, unchecked are not
Checked exceptions are errors in the code, unchecked are system errors
There is no difference
Q50
Q50 Analyze the output of this code snippet:
try {
int[] arr = new int[5];
arr[10] = 100;
System.out.println("Value set");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Index Error");
}
Value set
Index Error
Error
None
Q51
Q51 Determine the output of this pseudocode:
TRY PRINT "Start" THROW NEW EXCEPTION "Failed" CATCH EXCEPTION PRINT "Caught" END TRY PRINT "End"
Start Caught End
Start Failed
Caught
Start Caught
Q52
Q52 Identify the issue in this code snippet:
try {
int x = 5 / 0;
}
catch (Exception e) {
e.printStackTrace();
}
finally {
System.out.println("Done");
}
Division by zero
No error
Missing throw statement
Syntax error
Q53
Q53 Find the error in this Java code:
try {
File file = new File("test.txt");
FileReader fr = new FileReader(file);
}
catch (FileNotFoundException e) {
System.out.println("File not found");
}
File not found
No error
Missing import statements for File and FileReader
Syntax error
Q54
Q54 Identify the flaw in this Java code:
class CustomException extends Exception { }
try {
throw new CustomException();
}
catch (CustomException e) {
System.out.println("Custom exception caught");
}
CustomException should not be caught
CustomException should extend RuntimeException
Missing try block
No error
Q55
Q55 What are generics in Java?
Templates for creating collections
Special methods in Java
Memory allocation techniques
Data types in Java
Q56
Q56 Which collection type does not allow duplicate elements?
ArrayList
Vector
Set
List
Q57
Q57 Analyze the output of this code snippet:
List
list.add("Java");
list.add("Java");
System.out.println(list.get(1));
Java
Error
null
None
Q58
Q58 What will be the result of this pseudocode?
CREATE map SET map["Java"] = 1 SET map["Python"] = 2 SET map["Java"] = 3 PRINT map["Java"]
1
2
3
Error
Q59
Q59 What will this pseudocode output?
CREATE map SET map[1] = "Java" SET map[2] = "Python" SET map[1] = "C++" PRINT map[1]
Java
Python
C++
Error
Q60
Q60 Spot the mistake:
Set
TreeSet does not allow null
No error
Set should be HashSet
Syntax error

