Question 53Asked in DSSSB 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.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

This is question 53 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.