Java Programming - Java Strings Questions and Answers

Related Topics:

Java Programming : Java Strings

Java Programming Questions and answers on String in the form of MCQ. Each Question have 4 options with one correct answer.
1. String is an________
[A] class
[B] Variable
[C] Array
[D] Data type

Answer: A. class

2. import myLibrary.*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program?
[A] .
[C] ShowSomeClass
[D] ShowSomeClass.class

Answer: B.

3. Consider the following code snippet String river = new String('Columbia”); System.out.println(river.length()); What is printed?
[A] 6
[B] 7
[C] 8
[D] river

Answer: C. 8

4. : If s = "text", what is the value returned by s.length()?
[A] 4
[B] 5
[C] True
[D] False

Answer: A. 4

5. What is the difference between a TextArea and a TextField?
[A] A TextArea can handle multiple lines of text
[B] A textarea can be used for output
[C] TextArea is not a class
[D] TextAreas are used for displaying graphics

Answer: A. A TextArea can handle multiple lines of text

6. Given the following code fragment: int A[]; int i = 0; A = new int A[4]; while (i < 4) { A[i] = 10; i = i + 1; } What is the value of A[3]?
[A] 0
[B] 3
[C] 10
[D] unknown

Answer: C. 10

7. Given the following statement: huey.setDouble(8.0*32.2+1.0); What must be the data type of huey?
[A] Double Field
[B] Text Field
[C] Int field
[D] Double

Answer: A. Double Field

8. : A compound statement is:
[A] A collection of one or more statements enclosed in braces
[B] A statement involving if and else
[C] A way of declaring variables
[D] a way of setting the value of a variable

Answer: A. A collection of one or more statements enclosed in braces

9. Which of these method of String class is used to obtain character at specified index?
[A] char()
[B] Charat()
[C] charat()
[D] charAt()

Answer: D. charAt()

10. Which of these method of String class can be used to test to strings for equality?
[A] isequal()
[B] isequals()
[C] equal()
[D] equals()

Answer: D. equals()

Comments: (Your feedback is valuable to us)

Mido 6 months ago Reply

q 12 should compile!

Sanket Ghodke 8 months ago Reply

good one

M S REVATHI 1 year ago Reply

good job

Gidraf Kungu 1 year ago Reply


yogesh rawat 1 year ago Reply


Debjit Rowdian Banerjee 1 year ago Reply


alpesh sakhanpara 1 year ago Reply