Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  Which of these methods can be used to convert all characters in a String into a character array?

a. charAt()

b. both getChars() & charAt()

c. both toCharArray() & getChars()

d. all of the mentioned


Answer- both toCharArray() & getChars()


Que-  Which of these method of class String is used to compare two String objects for their equality?

a. equals()

b. Equals()

c. isequal()

d. Isequal()


Answer- equals()


Que-  Which of these methods is used to compare a specific region inside a string with another specific region in another string?

a. regionMatch()

b. match()

c. RegionMatches()

d. regionMatches()


Answer- regionMatches()


Que-  Which of these methods of class String is used to check whether a given object starts with a particular string literal?

a. startsWith()

b. endsWith()

c. Starts()

d. ends()


Answer- startsWith()


Que-  What is the value returned by function compareTo() if the invoking string is less than the string compared?

a. zero

b. value less than zero

c. value greater than zero

d. none of the mentioned


Answer- value less than zero


Que-  Which of these data type value is returned by equals() method of String class?

a. char

b. int

c. boolean

d. all of the mentioned


Answer- boolean


Que-  Which of this method of class String is used to extract a substring from a String object?

a. substring()

b. Substring()

c. SubString()

d. None of the mentioned


Answer- substring()


Que-  What will s2 contain after following lines of Java code? String s1 = "one"; String s2 = s1.concat("two")

a. one

b. two

c. onetwo

d. twoone


Answer- onetwo


Que-  Which of these method of class String is used to remove leading and trailing whitespaces?

a. startsWith()

b. trim()

c. Trim()

d. doTrim()


Answer- trim()


Que-  What is the value returned by function compareTo() if the invoking string is greater than the string compared?

a. zero

b. value less than zero

c. value greater than zero

d. none of the mentioned


Answer- value greater than zero


Que-  Which of the following statement is correct?

a. replace() method replaces all occurrences of one character in invoking string with another character

b. replace() method replaces only first occurrences of a character in invoking string with another character

c. replace() method replaces all the characters in invoking string with another character

d. replace() replace() method replaces last occurrence of a character in invoking string with another character


Answer- replace() method replaces all occurrences of one character in invoking string with another character


Que-  Which of these class is used to create an object whose character sequence is mutable?

a. String()

b. StringBuffer()

c. String() & StringBuffer()

d. None of the mentioned


Answer- StringBuffer()


Que-  Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

a. concat()

b. append()

c. join()

d. concatenate()


Answer- append()


Que-  Which of these method of class StringBuffer is used to find the length of current character sequence?

a. length()

b. Length()

c. capacity()

d. Capacity()


Answer- length()


Que-  What is the string contained in s after following lines of Java code? StringBuffer s new StringBuffer("Hello"); s.deleteCharAt(0);

a. Hell

b. ello

c. Hel

d. llo


Answer- ello


Que-  Which of the following statement is correct?

a. reverse() method reverses all characters

b. reverseall() method reverses all characters

c. replace() method replaces first occurrence of a character in invoking string with another character

d. replace() method replaces last occurrence of a character in invoking string with another character


Answer- reverse() method reverses all characters


Que-  Which of these methods of class StringBuffer is used to extract a substring from a String object?

a. substring()

b. Substring()

c. SubString()

d. None of the mentioned


Answer- substring()


Que-  What will s2 contain after following lines of Java code?  StringBuffer s1 = "one";  StringBuffer s2 = s1.append("two")

a. one

b. two

c. onetwo

d. twoone


Answer- onetwo


Que-  Which of this method of class StringBuffer is used to reverse sequence of characters?

a. reverse()

b. reverseall()

c. Reverse()

d. reverseAll()


Answer- reverse()


Que-  Which of this method of class StringBuffer is used to get the length of the sequence of characters?

a. length()

b. capacity()

c. Length()

d. Capacity()


Answer- length()


Que-  Which of the following are incorrect form of StringBuffer class constructor?

a. StringBuffer()

b. StringBuffer(int size)

c. StringBuffer(String str)

d. StringBuffer(int size , String str)


Answer- StringBuffer(int size , String str)


Que-  Which of these classes is not included in java.lang?

a. Byte

b. Integer

c. Array

d. Class


Answer- Array


Que-  Which of these is a process of converting a simple data type into a class?

a. type wrapping

b. type conversion

c. type casting

d. none of the Mentioned


Answer- type wrapping


Que-  Which of these is a super class of wrappers Double & Integer?

a. Long

b. Digits

c. Float

d. Number


Answer- Number


Que-  Which of these is a wrapper for simple data type float?

a. float

b. double

c. Float

d. Double


Answer- Float


Que-  Which of the following is a method of wrapper Float for converting the value of an object into byte?

a. bytevalue()

b. byte byteValue()

c. Bytevalue()

d. Byte Bytevalue()


Answer- byte byteValue()

Previous Post Next Post