Java Programming Fundamentals

Test your knowledge of Java programming concepts including collections, generics, inheritance, operators, and language syntax.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following is not a reserved keywords?

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

What is the value of the expression (1 / 2 + 3 / 2 + 0.1)?

  1. 1
  2. 1.1
  3. 1.6
  4. 2.1
Question 3 True/False

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 4 Multiple Choice (Multiple Answers)

Which of the following operators can be used both as an integer bitwise operator and a boolean logical operator?

  1. ^
  2. !
  3. &
  4. |
Question 5 Multiple Choice (Single Answer)

Which one of these is a valid method declaration?

  1. void method1 { /* ... */ }
  2. void method2() { /* ... */ }
  3. void method3(void) { /* ... */ }
  4. method4() { /* ... */ }
Question 6 True/False

Any problem in generic code is handled at Runtime.

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

Which one of the following class definitions is a valid definition of a class that cannot be extended?

  1. abstract class Link { }
  2. native class Link { }
  3. final class Link { }
  4. abstract final class Link { }
Question 8 Multiple Choice (Single Answer)

Which of these combinations of switch expression types and case label value types are legal within a switch statement?

  1. switch expression of type int and case label value of type char
  2. switch expression of type float and case label value of type int
  3. switch expression of type byte and case label value of type float
  4. switch expression of type char and case label value of type long
Question 9 Multiple Choice (Multiple Answers)

Which statements are true?

  1. {{}} is a valid statement block
  2. { continue; } is a valid statement block
  3. block: { break block; } is a valid statement block
  4. block: { continue block; } is a valid statement block
Question 10 Multiple Choice (Single Answer)

List l = new Arraylist(); if you use this line in your code what will we get?

  1. Compilation error.
  2. Runtime error
  3. Compiles Fine
  4. Depends on the code where you use
Question 11 Multiple Choice (Multiple Answers)

Which statements are true?

  1. Inheritance defines a has-a relationship between a superclass and its subclasses
  2. Every Java object has a public method named equals
  3. A class can extend any number of other classes
  4. A non-final class can be extended by any number of classes
Question 12 True/False

public void addAnimal(List animals) { animals.add(new Dog()); } it's NOT legal to add when we use Wildcard character .(True/ False)

  1. True
  2. False
Question 13 True/False

public void addAnimal(List animals) { animals.add(new Dog()); } it's NOT legal to add when we use Wildcard character .(True/ False)

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

List l = new Arraylist(); if you use this line in your code what will we get?

  1. Runtime error.
  2. Depends on the code where you use
  3. Compiles Fine
  4. Compilation error.
Question 15 True/False

1.Set s = new HashSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 16 True/False

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 17 True/False

1.Set s = new HashSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 18 True/False

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 19 True/False

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False
Question 20 True/False

1.Set s = new TreeSet(); 2.s.add("JAVA"); 3.s.add(new Integer(5)); Line 3 will give ClassCast Exception because Two different types of object are getting added.

  1. True
  2. False