Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet19/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   15   16   17   18   19   20   21   22   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

040.
041.
Answer:
The above code compiles fine and produces the following output:
Java100200
Since the ‘+’ operator is used with a String and int variables, the
final value is considered as a String and the values are
concatenated and displayed.
Explain the % operator.
Answer:
The % operator is called as the modulus or remainder operator. It
returns the remainder obtained after dividing the number on the
left with the number on the right. The following code
demonstrates this:
100 % 4 //produces 0
10 % 4 // produces 2
What will be the output of the following code?
final int iIntFinal = 100;
int iValue = iIntFinal ++;
System.out.println(“The output is– “+iValue);
Answer:
The code will cause a compilation error. This is because the code
tries to increment the final variable iIntFinal using the
increment operator. A final variable cannot be modified. The code
will work fine if the final variable is simply assigned to the
iValue variable.


042.
043.
Explain what happens when the following code is
compiled and executed?
int iValue = 100;
if(iValue = 100) { //line 1
System.out.println(“iValue is: “+iValue);
}
Answer:
The above code will cause a compilation error. At line 1, the
assignment operator = is used and not the comparison operator
==. So, this assigns the value 100 to the variable iValue and
produces an int result. The if condition cannot operate on an int
value, it requires a boolean value to test.
Will the below code compile? If so, what will be the
output?
int [] iArray = new int[10];
if(iArray instanceof Object) { //Line 1
System.out.println(“Object”);
}
else
{
System.out.println(“int”);
}
Answer:
The above code compiles fine and it displays the following
output:
Object



Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   15   16   17   18   19   20   21   22   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling