...
OOPS
August 25, 2024
OOPS
August 25, 2024
OOPS
August 25, 2024
OOPS
August 25, 2024

OOPS

Question 114
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;
A
X[P]=5 should be X(p)=5
B
P<=X.length() should be P<x.length()

</x.length()
C
X.length() should be X.length
D
P++ should be P+1
Question 114 Explanation: 
Integer data type we are using X.length and character data type we are using function X.length().
→ array.length : length is a final variable applicable for arrays. With the help of length variable, we can obtain the size of the array.
→ string.length() : length() method is a final variable which is applicable for string objects. length() method returns the number of characters presents in the string.
Correct Answer: C
Question 114 Explanation: 
Integer data type we are using X.length and character data type we are using function X.length().
→ array.length : length is a final variable applicable for arrays. With the help of length variable, we can obtain the size of the array.
→ string.length() : length() method is a final variable which is applicable for string objects. length() method returns the number of characters presents in the string.

Leave a Reply

Your email address will not be published. Required fields are marked *