Java Fundamentals for Android Development Quiz Questions and Answers

When should you use a static method?

Answer :
  • When you want your method to be available independently of class instances

Which keyword lets you use an interface?

Answer :
  • implements

Which operator is used to concatenate Strings in Java?

Answer :
  • +

What would be the output of the following code? class Main { public static void main(String[] args) { int x = 5; x = 10; System.out.println(x); } }

Answer :
  • 10

What would be the output of the following code? class Main { static int count = 0; public static void main(String[] args) { if (count < 3) { count++; main(null); } else { return; } System.out.println( "Hello World! "); } }

Answer :
  • It will print "Hello World! " three times

Which type of variable keeps a constant value once it is assigned?

Answer :
  • final

What would be the output of the following code? class Main { public static void main(String[] args) { char c = 'x'; System.out.println((int) c); } }

Answer :
  • a positive number

You get a NullPointerException. What is the most likely cause?

Answer :
  • The object you are using has not been instantiated.

Which statements about abstract classes are true? 1. They can be instantiated. 2. They allow member variables and methods to be inherited by subclasses. 3. They can contain constructors.

Answer :
  • 2 and 3

What would be the output of the following code? class Solution { public static void main(String[] args) { int a = 1; int b = 0; int c = a / b; System.out.println(c); } }

Answer :
  • It will throw an ArithmeticException