DSSSB TGT / PGT · Computer Science

Java Previous Year Questions

45 Java (Computer Science) questions asked in DSSSB TGT / PGT previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.

  • 45 questions
  • Official answer key
  • Free

Other Computer Science topics

Q1From DSSSB TGT Computer Science Practice Set 5
What correction is required for following Java code snippet to compile? int [] X = new int [10]; for (int P = 0; P<= X.length(); P++) X [P] = 5;
  1. AX [P] = 5 should be X (P) = 5
  2. BP<= X.length() should be P< X.length()
  3. CX.length() should be X.length
  4. DP++ should be P+1
Show answerHide answer

Correct answer: (C) X.length() should be X.length

Explanation

In Java, length is a field of an array, not a method, so X.length() will not compile and must be X.length. The <= would only cause a runtime exception, not a compile error.

Q2From DSSSB TGT Computer Science Practice Set 4
Consider the following Java code segment: public class while /* line 1*/ { public void loop ( ) { int x = 0; While (1)/* line-6*/ { system. out. println("x plus one is" + (x+1)): } } } Which of the following is true ?
  1. AThere is a syntax error in line-1
  2. BThere are syntax errors in line- 1 and line- 6
  3. CThere is a syntax error in line- 6
  4. DNo syntax error
Show answerHide answer

Correct answer: (A) There is a syntax error in line-1

Explanation

while is a reserved keyword in Java, so it cannot be used as a class name. "public class while" is a syntax error on line 1.

Q3From DSSSB TGT Computer Science Practice Set 3
The statements string var1[ ]; var1 = new string[3]; system.out.println (var1[1]); print
  1. AAn empty string
  2. BNull
  3. C0
  4. DA garbage character
Show answerHide answer

Correct answer: (B) Null

Explanation

new String[3] creates an array of references, and each element starts with the default value null. So printing var1[1] prints null.

Q4From DSSSB TGT Computer Science Practice Set 2
Which of the following methods in Java Script will display a window having a dialog box with a specified message, along with an OK and CANCEL button as options?
  1. Aprompt ()
  2. Balert ()
  3. Cconfirm ()
  4. Drequest ()
Show answerHide answer

Correct answer: (C) confirm ()

Explanation

confirm() shows a dialog with a message and OK and Cancel buttons and returns true or false. alert() has only OK, and prompt() also asks for text input.

Q5From DSSSB TGT Computer Science Practice Set 1
Java is a ______ language. This means that you must be explicit about what type of data you are working with.
  1. AWeakly typed
  2. BStrongly typed
  3. CDynamically typed
  4. DLoosely typed
Show answerHide answer

Correct answer: (B) Strongly typed

Explanation

Java is strongly (and statically) typed: every variable must be declared with a type, and the compiler does not allow values of incompatible types to be mixed without an explicit cast.

Q6DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
What is function of javap command?
  1. AA command for running the java compiler
  2. BA command that disassembles java class files
  3. CA command for running a non-optimized version of java compiler
  4. DA command that is used to generate API-style HTML documentation
Show answerHide answer

Correct answer: (B) A command that disassembles java class files

Explanation

javap is the Java class file disassembler. It shows the fields, methods and bytecode of a .class file. javac compiles and javadoc generates HTML docs.

Q7DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
Which of the following statement is/are correct regarding JAVA programming? I. A class marked as final cannot be inherited II. A method marked final cannot be overridden
  1. AOnly I
  2. BOnly II
  3. CBoth I and II
  4. DNeither I nor II
Show answerHide answer

Correct answer: (C) Both I and II

Explanation

In Java, a final class cannot be subclassed and a final method cannot be overridden. Both are correct.

Q8DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
What is the output of the following JAVA code? String s = "exam" + 9 + 9 + 9; System.out.println(s);
  1. Aexam 27
  2. Bexam: 27
  3. Cexam: 9
  4. Dexam: 999
Show answerHide answer

Correct answer: (D) exam: 999

Explanation

With a String on the left, each + is string concatenation: "exam" + 9 gives "exam9", and so on, giving "exam999". The 9s are not added to 27.

Q9DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
Which of the following is/are correct about java programming? I. All functions in java must be members of some class II. Member functions are called methods in java
  1. AOnly I
  2. BOnly II
  3. CBoth I and II
  4. DNeither I nor II
Show answerHide answer

Correct answer: (C) Both I and II

Explanation

Java has no free-standing functions: every method must belong to a class, and member functions are called methods. Both are correct.

Q10DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2
What is the output of the following java code? int m = 1000; int k = 3000; while (++m < --k); System.out.println(m);
  1. AError
  2. B1000
  3. C2000
  4. D4000
Show answerHide answer

Correct answer: (C) 2000

Explanation

Each test increments m and decrements k. The loop stops when m >= k, which first happens at m = 2000, k = 2000 (1000 iterations). So 2000 is printed.

Q11DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
What is AJAX in ASP.NET?
  1. AAsynchronous JavaScript and XML
  2. BAssociated JavaScript and XML
  3. CAsynchronous java script and HTML
  4. DAssociated JavaScript and HTML
Show answerHide answer

Correct answer: (A) Asynchronous JavaScript and XML

Explanation

AJAX stands for Asynchronous JavaScript and XML: it updates parts of a page by exchanging data with the server in the background.

Q12DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
JAVA compiler translates source code into ________.
  1. ASymbolic code
  2. BAssembly code
  3. CByte code
  4. DHigh language code
Show answerHide answer

Correct answer: (C) Byte code

Explanation

The Java compiler (javac) translates source code into platform-independent bytecode (.class files), which the JVM then executes.

Q13DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Which of the following statement(s) is/are correct regarding java programming? I. Place a semicolon immediately after a method header. II. Define a method outside the braces of a class definition.
  1. AOnly I
  2. BOnly II
  3. CBoth I and II
  4. DNeither I nor II
Show answerHide answer

Correct answer: (D) Neither I nor II

Explanation

Both are common errors: a semicolon after a method header ends the declaration, and in Java every method must be defined inside the class body braces. Neither statement is correct.

Q14DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
What is the output of the given java code? byte x = 64, y; y = (byte) (x << 4); system.out.println(y);
  1. A0
  2. B128
  3. C256
  4. D32
Show answerHide answer

Correct answer: (A) 0

Explanation

x << 4 is 64 × 16 = 1024 = 0x400 (as int). Casting to byte keeps only the low 8 bits, 0x00, so y prints 0.

Q15DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3
Which HTML tag is used to embed Java script scripts in a page?
  1. A<script> tag
  2. B<embed> tag
  3. C<java> tag
  4. D<enable> tag
Show answerHide answer

Correct answer: (A) <script> tag

Explanation

JavaScript is placed in a page with the <script> tag, either inline or through src.

Q16DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
A java program that is embedded in HTML document and runs in the context of java capable browser is known as ________.
  1. AApplet
  2. BCanvas
  3. CDoctags
  4. DFrame Window
Show answerHide answer

Correct answer: (A) Applet

Explanation

An applet is a small Java program embedded in an HTML page and run by a Java-enabled browser.

Q17DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
Which of the following is a wrapper class in Java?
  1. AInteger
  2. Bchar
  3. Cboolean
  4. Dfloat
Show answerHide answer

Correct answer: (A) Integer

Explanation

Integer is the wrapper class for the primitive int. char, boolean and float are primitive types, whose wrappers are Character, Boolean and Float.

Q18DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
Which among the following is the primary purpose of using interfaces in Java?
  1. ATo avoid creating objects
  2. BTo achieve multiple inheritance
  3. CTo improve user experience
  4. DTo reduce memory usage
Show answerHide answer

Correct answer: (B) To achieve multiple inheritance

Explanation

A Java class can extend only one class but can implement many interfaces. Interfaces are therefore Java's way of achieving multiple inheritance of type.

Q19DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
What will be the output of the following code? class Test { Test(int x) { System.out.println("Parameterized Constructor"); } Test() { this(10); System.out.println("Default Constructor"); } public static void main(String[] args) { Test obj = new Test(); } }
  1. AParameterized Constructor followed by Default Constructor
  2. BCompilation Error
  3. CDefault Constructor
  4. DParameterized Constructor
Show answerHide answer

Correct answer: (A) Parameterized Constructor followed by Default Constructor

Explanation

new Test() calls the no-argument constructor. Its first statement, this(10), runs the parameterized constructor first, so "Parameterized Constructor" is printed and then "Default Constructor".

Q20DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
Which of the following is NOT a valid identifier in Java?
  1. Amyvar123
  2. B_myvar
  3. Cstatic
  4. Dmy_var123
Show answerHide answer

Correct answer: (C) static

Explanation

static is a reserved keyword in Java and cannot be an identifier. Letters, digits (not first), _ and $ are allowed.

Q21DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
What will be the output of the following code? public class ExceptionDemo { public static void main(String[] args) { try { int[] numbers = {1, 2, 3}; System.out.println(numbers[5]); } catch (Exception e) { System.out.println("Exception caught: " + e.getClass().getName()); } finally { System.out.println("Execution completed."); } } }
  1. AException caught: java.lang.Exception . Execution completed.
  2. BException caught: java.lang.ArrayIndexOutOfBoundsException. Execution completed.
  3. CCompilation error
  4. DException caught: java.lang.IndexOutOfBoundsException . Execution completed.
Show answerHide answer

Correct answer: (B) Exception caught: java.lang.ArrayIndexOutOfBoundsException. Execution completed.

Explanation

numbers[5] is past the end of the array, so an ArrayIndexOutOfBoundsException is thrown. getClass().getName() gives its full name, and finally always runs.

Q22DSSSB TGT Computer Science (Technical), 13 Sep 2025, Shift 3 (5:00 PM)
Which of the following is used to include JavaScript code within an HTML document?
  1. A<js>
  2. B<script>
  3. C<javascript>
  4. D<java>
Show answerHide answer

Correct answer: (B) <script>

Explanation

JavaScript is placed in HTML inside <script> ... </script> tags, either inline or with the src attribute.

Q23DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
int a = 4, b = 8, c = 6; if (a > b) { if (a > c) { System.out.println("a is the largest"); } else if (b > c) { System.out.println("b is the largest"); } else { System.out.println("c is the largest"); } } else { if (b > c) { System.out.println("b is the largest"); } else { System.out.println("c is the largest"); } } What is the output of the above code snippet( Assume that it is written inside main() function )?
  1. Ac is the largest
  2. Bb is the largest
  3. Ca is the largest
  4. DCompilation error
Show answerHide answer

Correct answer: (B) b is the largest

Explanation

a > b (4 > 8) is false, so the outer else block runs. There b > c (8 > 6) is true, so "b is the largest" is printed.

Q24DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
Which method binding is associated with method overriding in Java?
  1. AStatic binding
  2. BDynamic binding
  3. CEarly binding
  4. DCompile-time binding
Show answerHide answer

Correct answer: (B) Dynamic binding

Explanation

Method overriding is resolved at run time from the actual object type. This is dynamic (late) binding, the basis of runtime polymorphism. Static or early binding is used for overloading, private, static and final methods.

Q25DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
class Person { private String name; public Person(String name) { this.name = name; } private void displayName() { System.out.println("Name: " + name); } } public class Test { public static void main(String[] args) { Person p = new Person("John"); p.displayName(); } } What will happen when the above code is compiled and executed?
  1. ACompilation Error: The method displayName is not visible in Test.
  2. BRuntime Error: The method displayName cannot be called.
  3. CThe code will compile and display Name: John.
  4. DCompilation Error: The field name is not visible in Test.
Show answerHide answer

Correct answer: (A) Compilation Error: The method displayName is not visible in Test.

Explanation

displayName() is private in Person, so it cannot be called from class Test. The compiler reports that displayName() has private access in Person.

Q26DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
What will be the output of the following Java code? public class DoWhileExample { public static void main(String[] args) { int x = 10; do { System.out.println("x = " + x); x++; } while (x < 13); } }
  1. Ax = 10 x = 11 x = 12
  2. Bx = 10
  3. Cx = 10 x = 11
  4. DNo output
Show answerHide answer

Correct answer: (A) x = 10 x = 11 x = 12

Explanation

A do-while body runs before the test: it prints x = 10, 11 and 12, and stops when x becomes 13 because 13 < 13 is false.

Q27DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
Consider the below Code snippet: class Calculator { void calculate(int a, int b) { class Multiply { int product() { return a * b; } } Multiply multiply = new Multiply(); System.out.println("Product: " + multiply.product()); } } public class Main { public static void main(String[] args) { Calculator calculator = new Calculator(); calculator.calculate(5, 3); } } What will be the output?
  1. AProduct: 15
  2. BProduct: 0
  3. CRuntime Error.
  4. DCompilation Error: Multiply cannot be defined inside calculate.
Show answerHide answer

Correct answer: (A) Product: 15

Explanation

Java allows a local class inside a method, and it can use the method's effectively final parameters a and b. product() returns 5 × 3 = 15, so "Product: 15" is printed.

Q28DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
What will be the output of the following Java code? public class IfExample { public static void main(String[] args) { int number = 10; if (number > 5) { System.out.println("Number is greater than 5"); } } }
  1. ANumber is less than 5
  2. BCompilation error
  3. CNumber is greater than 5
  4. DNo output
Show answerHide answer

Correct answer: (C) Number is greater than 5

Explanation

number = 10, so number > 5 is true and the if block prints "Number is greater than 5".

Q29DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)
Which of the following is the correct way to define a function in Java?
  1. Apublic void myFunction() {}
  2. Bfunction myFunction() {}
  3. Cdef myFunction() {}
  4. DPublic myFunction() {}
Show answerHide answer

Correct answer: (A) public void myFunction() {}

Explanation

In Java a method needs a return type, as in public void myFunction() {}. "function" is JavaScript syntax, "def" is Python, and "Public" (capital P) with no return type is invalid.

Q30DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
Consider the following Java code snippet: class Animal { String name; int age; Animal() { this.name = "Unknown"; this.age = 0; } Animal(String name, int age) { this.name = name; this.age = age; } void displayInfo() { System.out.println("Animal: " + name + ", Age: " + age); } } public class Main { public static void main(String[] args) { Animal a1 = new Animal(); Animal a2 = new Animal("Dog", 5); a1.displayInfo(); a2.displayInfo(); // Error-prone code: //1. Animal a3 = new Animal("Cat"); //2. a2.name = null; a2.displayInfo(); // 3. Animal a4 = null; a4.displayInfo(); } } Which of the following statements is/are true regarding the above code? 1. The Animal class supports both default and parameterized constructors. 2. If line 1 in the comment is uncommented, the code will compile and run successfully. 3. If line 2 is executed, a2.displayInfo() will print "Animal: null, Age: 5". 4. If line 3 is executed, the program will throw a NullPointerException at runtime.
  1. A1 and 4 only
  2. B2 only
  3. C1,2 and 4 only
  4. D1,3 and 4 only
Show answerHide answer

Correct answer: (D) 1,3 and 4 only

Explanation

1 is true (no-arg and two-arg constructors). 2 is false: there is no Animal(String) constructor, so it would not compile. 3 is true: concatenating null prints "null". 4 is true: calling a method on a null reference throws NullPointerException.

Q31DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
Which of the following demonstrates the implementation of inheritance in Java?
  1. Aclass B inherits A {}
  2. Bclass A contains B {}
  3. Cclass A implements B {}
  4. Dclass A extends B {}
Show answerHide answer

Correct answer: (D) class A extends B {}

Explanation

Java uses the keyword extends for class inheritance, e.g. class A extends B. implements is used when a class implements an interface; inherits and contains are not Java keywords.

Q32DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
Given the following code, what will be the result? public class Test { public static void main(String[] args) { Object obj = new String("Hello"); String str = (String) obj; System.out.println(str); } }
  1. AThrows ClassCastException.
  2. BRuntime error.
  3. CHello will be printed.
  4. DCompilation error.
Show answerHide answer

Correct answer: (C) Hello will be printed.

Explanation

obj actually refers to a String object, so the downcast (String) obj succeeds at run time and "Hello" is printed. ClassCastException occurs only when the object is not of the target type.

Q33DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
Which among the following is an example of compile-time polymorphism in Java?
  1. AMethod overriding
  2. BInterfaces
  3. CAbstract classes
  4. DMethod overloading
Show answerHide answer

Correct answer: (D) Method overloading

Explanation

Method overloading (same name, different parameter lists) is resolved by the compiler, so it is compile-time (static) polymorphism. Method overriding is resolved at run time.

Q34DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
What is the output of the following code snippet? int x = 6; System.out.println(x++ + ++x);
  1. A12
  2. B14
  3. C11
  4. D13
Show answerHide answer

Correct answer: (B) 14

Explanation

x++ gives 6 and makes x 7; ++x then makes x 8 and gives 8. So 6 + 8 = 14.

Q35DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)
Which of the following is the correct way to declare a variable in Java?
  1. Alet x = 10;
  2. Bx = 10;
  3. Cvar x = 10;
  4. Dint x = 10;
Show answerHide answer

Correct answer: (D) int x = 10;

Explanation

Java is statically typed, so a variable is declared with its type: int x = 10;. let is JavaScript, and var x = 10 works only as local type inference from Java 10, so the standard answer is int.

Q36DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)
class Parent { protected void protectedMethod() { System.out.println("Protected method in Parent"); } } class Child extends Parent { public void childMethod() { protectedMethod(); } } public class Test { public static void main(String[] args) { Child child = new Child(); child.childMethod(); } } What will happen when the code is executed?
  1. AThe code will compile and print 'Protected method in Parent'.
  2. BCompilation Error: The protectedMethod is not visible in the Child class.
  3. CCompilation Error: childMethod is not visible due to access restrictions.
  4. DRuntime Error: Cannot access protectedMethod from the Child class.
Show answerHide answer

Correct answer: (A) The code will compile and print 'Protected method in Parent'.

Explanation

A protected member is accessible in a subclass, so Child can call protectedMethod() directly. The code compiles and prints "Protected method in Parent".

Q37DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)
What does the super keyword in Java do?
  1. ARefers to high performing objects
  2. BRefers to the current object
  3. CUsed to define static variables
  4. DRefers to the parent class
Show answerHide answer

Correct answer: (D) Refers to the parent class

Explanation

super refers to the immediate parent (superclass) object; it is used to call parent constructors and access parent methods or fields. The current object is referred to by this.

Q38DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)
public class ExceptionTest { public static void main(String[] args) { try { System.out.println("Result: " + calculate(10, 0)); } catch (ArithmeticException e) { System.out.println("ArithmeticException caught: " + e.getMessage()); } catch (Exception e) { System.out.println("General exception caught: " + e.getMessage()); } finally { System.out.println("In finally block."); } } public static int calculate(int a, int b) throws Exception { try { return a / b; } catch (ArithmeticException e) { throw new Exception("Division by zero not allowed"); } finally { System.out.println("Inner finally block executed."); } } } What will be the output of the program?
  1. AInner finally block executed. General exception caught: / by zero In finally block.
  2. BInner finally block executed. General exception caught: Division by zero not allowed In finally block.
  3. CInner finally block executed. Result: 0 In finally block.
  4. DInner finally block executed. ArithmeticException caught: / by zero In finally block.
Show answerHide answer

Correct answer: (B) Inner finally block executed. General exception caught: Division by zero not allowed In finally block.

Explanation

10/0 throws ArithmeticException inside calculate, which is caught and replaced by new Exception("Division by zero not allowed"). The inner finally prints first, then main's catch (Exception) prints that message, and finally main's finally block runs.

Q39DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)
What will be the output of the following program? class CustomException extends Exception { public CustomException(String message) { super(message); } } public class TestCustomException { public static void main(String[] args) { try { validateAge(15); } catch (CustomException e) { System.out.println("Caught Exception: " + e.getMessage()); } finally { System.out.println("Execution finished."); } } public static void validateAge(int age) throws CustomException { if (age < 18) { throw new CustomException("Age must be 18 or above."); } System.out.println("Age is valid."); } }
  1. ACaught Exception: null Execution finished.
  2. BCompilation error because custom exceptions cannot extend Exception.
  3. CAge is valid. Execution finished.
  4. DCaught Exception: Age must be 18 or above. Execution finished.
Show answerHide answer

Correct answer: (D) Caught Exception: Age must be 18 or above. Execution finished.

Explanation

validateAge(15) throws CustomException with the message "Age must be 18 or above.", so "Age is valid." is never printed. The catch prints the message and the finally block prints "Execution finished.".

Q40DSSSB TGT Computer Science, 25 Jun 2023, Shift 1 (8:30 AM)
What is the output of the following java program? public class Solution{ public static void main(String[] args){ int[] p = {121, 201, 017}; for(int j = 0; j < p.length; j++){ System.out.print(p[j] + " "); } } }
  1. A1121 201 17
  2. B1121 201 15
  3. CCompilation error
  4. DRuntime error
Show answerHide answer

Correct answer: (B) 1121 201 15

Explanation

A leading 0 makes 017 an octal literal, which equals 15. The program prints 121 201 15, which is option (B) (its text shows a stray leading 1).

Q41DSSSB TGT Computer Science, 24 Jun 2023, Shift 3 (4:30 PM)
______ does NOT have any child ClassLoaders.
  1. ABootStrap ClassLoader
  2. BExtension ClassLoader
  3. CPrimordial ClassLoader
  4. DSystem ClassLoader
Show answerHide answer

Correct answer: (D) System ClassLoader

Explanation

The class-loader hierarchy is Bootstrap (Primordial) → Extension → System (Application). The System ClassLoader is at the bottom, so by default it has no child class loaders.

Q42DSSSB TGT Computer Science, 24 Jun 2023, Shift 3 (4:30 PM)
Which of the following is an example of the fifth-generation language?
  1. AJava
  2. BCobol
  3. Cprolog
  4. DPython
Show answerHide answer

Correct answer: (C) prolog

Explanation

Fifth-generation languages, such as Prolog, solve problems using constraints and logic rules instead of step-by-step algorithms. Java, COBOL and Python are third-generation languages.

Q43DSSSB TGT Computer Science, 24 Jun 2023, Shift 3 (4:30 PM)
What is the output of the following code? int Integer = 24; char String = 'I'; System.out.print(Integer); System.out.print(String);
  1. AI
  2. BCompiler Error
  3. CThrows Exception
  4. D24I
Show answerHide answer

Correct answer: (D) 24I

Explanation

Integer and String are class names, not keywords, so they can be used as variable names. The code prints 24 and then I on the same line: 24I.

Q44DSSSB TGT Computer Science, 25 Jun 2023, Shift 3 (4:30 PM)
What will be the output of the following java program? class Example { public static void main(String args[ ]) { int a = 50; double b = 50.1; boolean x = (a == b); System.out.println(x); } }
  1. ACompilation error
  2. BFalse
  3. CTrue
  4. D50
Show answerHide answer

Correct answer: (A) Compilation error

Explanation

Note: the answer key gives (A), but the code compiles. In a == b the int is widened to double, and 50.0 == 50.1 is false, so the program prints "false" (option B).

Q45DSSSB TGT Computer Science, 25 Jun 2023, Shift 3 (4:30 PM)
In which of the following does the JDBC type represent a 'single precision' floating point number that supports seven digits of mantissa?
  1. ADOUBLE
  2. BREAL
  3. CFLOAT
  4. DINTEGER
Show answerHide answer

Correct answer: (B) REAL

Explanation

The JDBC type REAL is a single-precision floating-point number with 7 digits of mantissa (Java float). FLOAT and DOUBLE are double precision with 15 digits.

How to use these DSSSB TGT / PGT Computer Science questions

Every question here was asked in a real DSSSB TGT / PGT paper; the paper and shift are shown on the card, and the number opens the question on its own page. Try each one before tapping Show answer, then attempt the full DSSSB TGT / PGT papers as timed tests to check your speed under exam conditions.

More DSSSB TGT / PGT subjects