Java Programming Fundamentals

Test your knowledge of Java programming language concepts including exception handling, compilation, inheritance, access modifiers, keywords, threading, and applets.

20 Questions Published

Questions

Question 1 True/False

A static method can refer to any instance variable of the class.

  1. True
  2. False
Question 2 Multiple Choice (Single Answer)

Java runs on

  1. Windows
  2. Unix/Linux
  3. Macs
  4. All of the Above
Question 3 Multiple Choice (Single Answer)

An applet will run in almost any browser because

  1. The server has a built-in JVM
  2. The browser has a built-in JVM
  3. The source code is interpreted by the browser
  4. Applets don''t need a JVM.
Question 4 Multiple Choice (Single Answer)

What is an Applet?

  1. An interactive website
  2. A Java program that is run through a web browser
  3. A type of computer
  4. A type of fruit
Question 5 Multiple Choice (Single Answer)

What is Java?

  1. A type of coffee
  2. An object-oriented programming language
  3. An interactive website
  4. None of the above
Question 6 Multiple Choice (Single Answer)

The BorderLayout class provides static fields for

  1. Introducing new methods
  2. Adding components to specific areas of a container
  3. Starting an applet
  4. Specifying font size and color
Question 7 Multiple Choice (Single Answer)

What is the advantage of using import statements?

  1. To avoid having to declare variables
  2. To refer to a class without using prefixes
  3. To avoid calling methods
  4. To import the images you want to use
Question 8 Multiple Choice (Single Answer)

Which of the following statements about this code are true? class A extends Thread{ public void run(){ for(int i =0; i < 2; i++){ System.out.println(i); } } } public class Test{ public static void main(String argv[]){ Test t = new Test(); t.check(new A(){}); } public void check(A a){ a.start(); } }

  1. 0 0
  2. Compilation error, class A has no start method
  3. 0 1
  4. Compilation succeed but runtime exception
Question 9 Multiple Choice (Single Answer)

What is the output for the below code ? class A implements Runnable{ public void run(){ System.out.println("run-a"); } } 1. public class Test { 2. public static void main(String... args) { 3. A a = new A(); 4. Thread t = new Thread(a); 5. t.start(); 6. t.start(); 7. } 8. }

  1. run-a
  2. run-a run-a
  3. Compilation fails with an error at line 6
  4. Compilation succeed but Runtime Exception
Question 10 Multiple Choice (Single Answer)

What is the output for the below code ? public class Test { public static void main(String... args) { int a =5 , b=6, c =7; System.out.println("Value is "+ b +c); System.out.println(a + b +c); System.out.println("String "+(b+c)); } }

  1. Value is 67 18 String 13
  2. Value is 13 18 String 13
  3. Value is 13 18 String
  4. Compilation fails
Question 11 Multiple Choice (Single Answer)

What is the output for the below code ? 1. public class A { 2. int add(int i, int j){ 3. return i+j; 4. } 5.} 6.public class B extends A{ 7. public static void main(String argv[]){ 8. short s = 9; 9. System.out.println(add(s,6)); 10. } 11.}

  1. Compile fail due to error on line no 2
  2. Compile fail due to error on line no 9
  3. Compile fail due to error on line no 8
  4. 15
Question 12 Multiple Choice (Single Answer)

What is the output for the below code ? 1. public class Test { 2. public static void main(String[] args){ 3. int i = 010; 4. int j = 07; 5. System.out.println(i); 6. System.out.println(j); 7. } 8. }

  1. 8 7
  2. 10 7
  3. Compilation fails with an error at line 3
  4. Compilation fails with an error at line 5
Question 13 Multiple Choice (Multiple Answers)

Select correct answers

  1. The keyword extends is used to specify that an interface inherits from another interface.
  2. The keyword extends is used to specify that a class inherits from an interface.
  3. The keyword implements is used to specify that an interface inherits from another interface.
  4. The keyword implements is used to specify that a class inherits from an interface.
  5. The keyword implements is used to specify that a class inherits from another class.
Question 14 Multiple Choice (Multiple Answers)

Which of the following are reserved keywords in Java?

  1. public
  2. static
  3. void
  4. main
  5. String
Question 15 Multiple Choice (Single Answer)

How restrictive is the default accessibility compared to public, protected, and private accessibility in Java?

  1. Less restrictive than public
  2. More restrictive than public, but less restrictive than protected.
  3. More restrictive than protected, but less restrictive than private.
  4. More restrictive than private.
  5. Less restrictive than protected from within a package, and more restrictive than protected from outside a package.
Question 16 Multiple Choice (Single Answer)

Which of these are valid declarations of the main() method in order to start the execution of a Java application?

  1. static public void main(String[] args) { /* ... */ }
  2. public static int main(String[] args) { /* ... */ }
  3. public static void main(String args) { /* ... */ }
  4. public int main(Strings[] args, int argc) { /* ... */ }
Question 17 Multiple Choice (Single Answer)

In derived classes, in what order are the constructors called?

  1. from base to the derived class
  2. from derived to base
  3. only the derived class
  4. only the base class
Question 18 Multiple Choice (Multiple Answers)

Select correct answers

  1. A subclass must define all the methods from the superclass
  2. It is possible for a subclass to define a method with the same name and parameters as a method defined by the superclass.
  3. It is possible for a subclass to define a field with the same name as a field defined by the superclass.
  4. It is possible for two classes to be the superclass of each other.
Question 19 Multiple Choice (Single Answer)

What will be the result of attempting to compile this Java class?

  1. The class will fail to compile, since the class Other has not yet been declared when referenced in class AClass.
  2. The class will fail to compile, since import statements must never be at the very top of a file.
  3. The class will fail to compile, since the package declaration can never occur after an import statement.
  4. The class will fail to compile, since the class Other must be defined in a file called Other.java.
  5. The class will fail to compile, since the class Other must be declared public.
Question 20 True/False

If an exception is not caught, the finally block will run

  1. True
  2. False