Java MCQs with answers Page - 22

Here, you will find a collection of MCQ questions on Java. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 831.35K Points
Coach

Q. Identify the keyword among the following that makes a variable belong to a class,rather than being defined for each instance of the class.

  • (A) Final
  • (B) Static
  • (C) Volatile
  • (D) Abstract

A

Admin • 831.35K Points
Coach

Q. Identify what can directly access and change the value of the variable res.

Code:
Package com.mypackage;
Public class Solution{
       Private int res = 100;
}
  • (A) Any class
  • (B) Only solution class
  • (C) Any class that extends solution
  • (D) None

A

Admin • 831.35K Points
Coach

Q. In which of the following is toString() method defined?

  • (A) java.lang.Object
  • (B) java.lang.String
  • (C) java.lang.util
  • (D) None

A

Admin • 831.35K Points
Coach

Q. compareTo() returns

  • (A) True
  • (B) False
  • (C) An int vale
  • (D) None

A

Admin • 831.35K Points
Coach

Q. Identify the output of the following program

Code:
String str = “abcde”;
System.out.println(str.substring(1, 3));
  • (A) abc
  • (B) bc
  • (C) bcd
  • (D) cd

A

Admin • 831.35K Points
Coach

Q. Identify the output of the following program.

Code:
String str = “Hellow”;
System.out.println(str.indexOf(‘t));
  • (A) 0
  • (B) 1
  • (C) true
  • (D) -1

A

Admin • 831.35K Points
Coach

Q. Identify the output of the following program.

Code:
Public class Test{
          Public static void main(String argos[]){
                   String str1 = “one”;
                   String str2 = “two”;
                   System.out.println(str1.concat(str2));
          }
}
  • (A) one
  • (B) two
  • (C) ontwo
  • (D) twoone

A

Admin • 831.35K Points
Coach

Q. What does the following string do to given string str1.

Code:
String str1 = “chandrakant”.replace(‘c’,’s’);
  • (A) Replaces single occurance of c to s
  • (B) Replaces all occurance of c to s
  • (C) Replaces single occurance of s to c
  • (D) None

A

Admin • 831.35K Points
Coach

Q. To which of the following does the class string belong to.

  • (A) java.lang
  • (B) java.awt
  • (C) java.applet
  • (D) java.string

A

Admin • 831.35K Points
Coach

Q. The method used to set Fonts is

  • (A) Graphics
  • (B) Font
  • (C) Applet
  • (D) Component