Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
NullPointerException
:
Content language: English
Русский
What will be the result of the following code compilation and execution? public class Main { public static void main(String args[]) { ClassA a = new ClassA(); a.methodA(); } } class ClassA { public void methodA(){ ClassB classB = new ClassB(); System.out.println(classB.getValue()); } } class ClassB { public ClassC classC; public String getValue() { return classC.getValue(); } } class ClassC { public String value; public String getValue() { value = "ClassC"; return value; } }
NullPointerException
What will the following code print out to console? public class Test { private Integer k; private int z; private int i; public void method() { i = k + z; // 1 } public static void main(String[] args) { Test t = new Test(); t.method(); System.out.println(t.i); // 2 } }
NullPointerException
What will be printed out to console after the following class is compiled and executed: public class A { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(0); Integer[] array = null; list.toArray(array); System.out.println(list.get(1)); } }
NullPointerException
Will the code compile? If so, what will be the result of its implementation? public class Autoboxing { public static void main(String[] args) { Integer oInt1 = null; Integer oInt2 = 0; final int int1 = oInt1; final int int2 = oInt2; System.out.println(int1 == int2); } }
NullPointerException
What will be the output of the following program? class Person { public String name; public int age; public Person(String name, int age) { this.name = name; this.age = age; } public boolean equals(Object obj) { return obj instanceof Person && this.age == ((Person)obj).age && this.name.equals(((Person)obj).name); } } public class Quizful { public static void main(String[] args){ Person p1 = new Person(null, 10); Person p2 = new Person("Alex", 22); System.out.println(p1.equals(p2)); } }
NullPointerException
← Prev
1
Next →
Sign Up Now
or
Subscribe for future quizzes