Java Programming Fundamentals: OOP, Inheritance, and Language Features

Test your knowledge of core Java programming concepts including polymorphism, method overloading and overriding, exception handling, inheritance, static methods, final variables, garbage collection, and Java I/O operations.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following servlet methods can return null?

  1. getInitParameterNames()
  2. getInitParameter(String name)
  3. getServletName()
  4. getServletContext()
Question 2 True/False

Is Array operations are faster than Vector.

  1. True
  2. False
Question 3 True/False

Does File class have any method to read or write content in a file?

  1. True
  2. False
Question 4 True/False

Java Polymorphism

  1. True
  2. False
Question 5 True/False

Final variables declared without initialization can be initialized in static initializer ( static final var) or in constructor( final var). True/False?

  1. True
  2. False
Question 6 True/False

Is the following statement correct: char ch = 'd'; if(ch < 32.00){ }

  1. True
  2. False
Question 7 True/False

If there is an exception in finalize method, will the object be garbage collected?

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

If you have reference variable of parent class type and you assign a child class object to that variable and invoke static method. Which method will be invoked? Parent/Child.

  1. Parent
  2. Child
  3. Both
  4. None of these
Question 9 True/False

Can we declare derived class first and then base class in java?

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

byte b; final int a = 10; final int x = a; b = x; System.out.println("The value of b is " + b);

  1. Compilation error
  2. Runtime Error
  3. 10
  4. None of these
Question 11 Multiple Choice (Single Answer)

Which one of these statements are valid? Char \u0061r a =’a’; Char \u0062 = ’b’; Char c =’\u0063’Which one is not correct A. x = = Float.NaN B. Float.isNan(x); C. Myobject .equals(float.NaN);

  1. A
  2. B
  3. C
  4. All
Question 12 True/False

static methods can be overridden. True/False

  1. True
  2. False
Question 13 True/False

main method can be overridden.. True/False

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

Which one is not correct A. x = = Float.NaN B. Float.isNan(x); C. Myobject .equals(float.NaN);

  1. A
  2. B
  3. Both
  4. None of these
Question 15 Multiple Choice (Single Answer)

Which is true about overloading?

  1. return type should be different
  2. access speciifer should be different
  3. arguments should be different
  4. the overloaded methods should throw a different excpetion
Question 16 Multiple Choice (Single Answer)

What is the rule regarding overriding methods throwing exceptions?

  1. Overriding method can not throw more generic exception than base method
  2. Overriding method can throw new or broader checked exceptions
  3. None of the above
  4. Both a and b
Question 17 Multiple Choice (Single Answer)

println exhibits which type of polymorphism

  1. Overloading
  2. Overriding
  3. Both 1 and 2
  4. Dynamic polymorphism
Question 18 Multiple Choice (Single Answer)

void main() { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); }

  1. not same
  2. same
  3. unknown symbol ‘~’
  4. none of the above
Question 19 Multiple Choice (Single Answer)

f1(int c) { printf("%d", c); } void main() { int a=1; f1(a++); }

  1. 0
  2. 1
  3. 2
  4. 3
Question 20 Multiple Choice (Single Answer)

main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p\t%p\t%p",p,q,r); }

  1. 0001 0002 0003
  2. compile error
  3. 0001 0002 0004
  4. 0001 0002 0006