Java Programming Fundamentals
Test your knowledge of core Java programming concepts including OOP, collections, multithreading, and language features.
Questions
Question 1 Multiple Choice (Single Answer)
- 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(); } } }
- text.txt will be created and overwrite the old file
- file will not be created
- exception will be thrown
- none of the above
Question 2 Multiple Choice (Multiple Answers)
- Select all the incorrect options:
- Since enums are comparable to traditional classes, they may not be arguments in switch statements.
- Enums may not extend another class/ enum.
- Enums inherit the java.lang.Object class.
- Enums may be extended by another Enum.
Question 3 Multiple Choice (Single Answer)
- How will you declare a timer variable that will be accessed by multiple threads very frequently?
- Declare the variable as volatile.
- not possible
- By java.util.*;
- By final keyword
Question 4 Multiple Choice (Single Answer)
- How will you remove duplicate element from a List?
- Add the List elements to Set
- List doesnt allow that
- using remove()
- none of these
Question 5 Multiple Choice (Single Answer)
- Abstract class can be initiated directly ?
- yes
- No
- sometimes only
- none of these
Question 6 Multiple Choice (Single Answer)
- Does a class inherit the constructors of its superclass?
- Using interface
- Class should be declared as private
- yes
- 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
- same thing no difference
- static block for particular object lock and static method locks all the object
- java doesnt have static block only static method it have
- none of these
Question 8 Multiple Choice (Single Answer)
which class is first called for all java class
- public void class
- object class
- inner class
- outer class
Question 9 True/False
java doesnot support pass by referrence only pass by value
- True
- False
Question 10 Multiple Choice (Single Answer)
Is it possible to extend the java.lang.String class?
- yes
- no java.lang.String is declared as final
- some times only
- none of these
Question 11 True/False
java doesnt supports global variables
- True
- 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.
- True
- False
Question 13 Multiple Choice (Single Answer)
what are the types of methods for object class
- wait(), toString() only
- notify(), notifyall() only
- run(), stop()
- wait(),toString(),notify(), notifyall() and finalize()