1. What will be the output?
public class TestStringInteger {
String s="a230";
int x=Integer.parseInt(s);
public static void main(String args[])
{
System.out.println(x);
}
}
Output:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NumberFormatException: For input string: "a230"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at packA.TestStringInteger.<clinit>(TestStringInteger.java:6)
2. What will be the output?
public class TestFloatInteger{
int val1 = (int) Math.round(3.6);
int val2 = (int) Math.round(3.4);
public static void main(String args[])
{
System.out.println(val1+val2);
}
}
Output:7
3. What will be the output?
public class Operators {
public static void main(String[] args) {
int a=5;
int c=a++ - --a;
System.out.println(c);
}
}
Output:0
4. What will be the output?
public class NoNull {
public static String foo(){
System.out.println("Test foo called");
return "";
}
public static void main(String args[]){
NoNull obj = null;
System.out.println(obj.foo());
}
}
Output: Test foo called
5.