Java Programming Fundamentals

Test your knowledge of core Java programming concepts including OOP, collections, multithreading, and language features.

13 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)
  1. Assume that in the current directory test.txt file is already exist. What will happen when you execute the following code? import java.io.*; class Test { public static void main(String args[]) { try { File file = new File("test.txt"); file.createNewFile(); } catch (IOException ex) { ex.printStackTrace(); } } }
  1. text.txt will be created and overwrite the old file
  2. file will not be created
  3. exception will be thrown
  4. none of the above
Question 2 Multiple Choice (Multiple Answers)
  1. Select all the incorrect options:
  1. Since enums are comparable to traditional classes, they may not be arguments in switch statements.
  2. Enums may not extend another class/ enum.
  3. Enums inherit the java.lang.Object class.
  4. Enums may be extended by another Enum.
Question 3 Multiple Choice (Single Answer)
  1. How will you declare a timer variable that will be accessed by multiple threads very frequently?
  1. Declare the variable as volatile.
  2. not possible
  3. By java.util.*;
  4. By final keyword
Question 4 Multiple Choice (Single Answer)
  1. How will you remove duplicate element from a List?
  1. Add the List elements to Set
  2. List doesnt allow that
  3. using remove()
  4. none of these
Question 5 Multiple Choice (Single Answer)
  1. Abstract class can be initiated directly ?
  1. yes
  2. No
  3. sometimes only
  4. none of these
Question 6 Multiple Choice (Single Answer)
  1. Does a class inherit the constructors of its superclass?
  1. Using interface
  2. Class should be declared as private
  3. yes
  4. A class does not inherit constructors from any of its superclasses.
Question 7 Multiple Choice (Single Answer)

what is difference between static block and static method

  1. same thing no difference
  2. static block for particular object lock and static method locks all the object
  3. java doesnt have static block only static method it have
  4. none of these
Question 8 Multiple Choice (Single Answer)

which class is first called for all java class

  1. public void class
  2. object class
  3. inner class
  4. outer class
Question 9 True/False

java doesnot support pass by referrence only pass by value

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

Is it possible to extend the java.lang.String class?

  1. yes
  2. no java.lang.String is declared as final
  3. some times only
  4. none of these
Question 11 True/False

java doesnt supports global variables

  1. True
  2. False
Question 12 True/False

main() method is declared as a static method so that it can be invoked without having to create an instance of the corresponding class.

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

what are the types of methods for object class

  1. wait(), toString() only
  2. notify(), notifyall() only
  3. run(), stop()
  4. wait(),toString(),notify(), notifyall() and finalize()