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.
Questions
Which of the following servlet methods can return null?
- getInitParameterNames()
- getInitParameter(String name)
- getServletName()
- getServletContext()
Is Array operations are faster than Vector.
- True
- False
Does File class have any method to read or write content in a file?
- True
- False
Java Polymorphism
- True
- False
Final variables declared without initialization can be initialized in static initializer ( static final var) or in constructor( final var). True/False?
- True
- False
Is the following statement correct: char ch = 'd'; if(ch < 32.00){ }
- True
- False
If there is an exception in finalize method, will the object be garbage collected?
- True
- False
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.
- Parent
- Child
- Both
- None of these
Can we declare derived class first and then base class in java?
- True
- False
byte b; final int a = 10; final int x = a; b = x; System.out.println("The value of b is " + b);
- Compilation error
- Runtime Error
- 10
- None of these
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);
- A
- B
- C
- All
static methods can be overridden. True/False
- True
- False
main method can be overridden.. True/False
- True
- False
Which one is not correct A. x = = Float.NaN B. Float.isNan(x); C. Myobject .equals(float.NaN);
- A
- B
- Both
- None of these
Which is true about overloading?
- return type should be different
- access speciifer should be different
- arguments should be different
- the overloaded methods should throw a different excpetion
What is the rule regarding overriding methods throwing exceptions?
- Overriding method can not throw more generic exception than base method
- Overriding method can throw new or broader checked exceptions
- None of the above
- Both a and b
println exhibits which type of polymorphism
- Overloading
- Overriding
- Both 1 and 2
- Dynamic polymorphism
void main() { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); }
- not same
- same
- unknown symbol ‘~’
- none of the above
f1(int c) { printf("%d", c); } void main() { int a=1; f1(a++); }
- 0
- 1
- 2
- 3
main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p\t%p\t%p",p,q,r); }
- 0001 0002 0003
- compile error
- 0001 0002 0004
- 0001 0002 0006