Part A: Methods / Functions (Q1–Q20) a) self
b) super
A function in Java is called: c) this
a) Procedure d) obj
b) Method Answer: c
c) Subroutine
d) Module The keyword used to call parent class method is:
Answer: b a) parent
b) super
Which keyword is used to define a method? c) base
a) def d) this
b) function Answer: b
c) void / return type
d) method A constructor is a special type of:
Answer: c a) Class
b) Method
A method that does not return any value uses return type: c) Object
a) null d) Keyword
b) int Answer: b
c) void
d) none The return type of a constructor is:
Answer: c a) void
b) int
Which keyword is used to return a value from a method? c) same as class
a) break d) none
b) return Answer: d
c) continue
d) stop Default constructor is provided by compiler when:
Answer: b a) We don’t write any constructor
b) We write at least one constructor
The parameters written inside method definition are called: c) Always
a) Arguments d) Never
b) Parameters / Formal parameters Answer: a
c) Variables
d) Identifiers Which of these is NOT a valid method name?
Answer: b a) add()
b) computeSum()
The values passed to a method during call are called: c) 123print()
a) Arguments / Actual parameters d) display()
b) Parameters Answer: c
c) Variables
d) Identifiers Which keyword is used to define a method that cannot be
Answer: a overridden?
a) final
Method overloading means: b) static
a) Same name, different parameters c) private
b) Same name, same parameters d) super
c) Different name, same parameters Answer: a
d) Different classes
Answer: a A method with the same name but different return type and
same parameters is:
Method overriding means: a) Valid overloading
a) Same method redefined in subclass b) Compilation error
b) Same name, different parameters c) Runtime error
c) Different name, same parameters d) None
d) None Answer: b
Answer: a
Which method is automatically called when object is
A method defined as static belongs to: destroyed?
a) Object a) finalize()
b) Class b) end()
c) Package c) delete()
d) Interface d) close()
Answer: b Answer: a
The keyword used to call current object is: Static methods can access:
a) Only instance variables b) Iteration
b) Only static variables c) Both same
c) Both d) Depends on compiler
d) None Answer: b
Answer: b
Which keyword is used to exit from a recursive call?
Methods in Java must always be defined inside: a) break
a) Object b) continue
b) Class c) return
c) Package d) exit
d) Interface Answer: c
Answer: b
Recursion is an example of:
Part B: Recursion (Q21–Q35) a) Abstraction
b) Polymorphism
A method that calls itself is called: c) Divide and Conquer
a) Loop d) Encapsulation
b) Recursive method Answer: c
c) Iterative method
d) Static method Recursive functions are memory intensive because:
Answer: b a) They use heap
b) They use stack frames
Which of the following is essential for recursion? c) They use static memory
a) Loop d) None
b) Base case Answer: b
c) Switch
d) Array The minimum requirement for recursion is:
Answer: b a) At least 2 functions
b) At least 1 base case
Without a base case, recursion will lead to: c) At least 1 loop
a) Compilation error d) At least 1 array
b) Infinite recursion Answer: b
c) Syntax error
d) None Direct recursion means:
Answer: b a) Method A calls Method B
b) Method A calls itself
Factorial of a number is best solved using: c) Method A calls Method B which calls Method A
a) Recursion d) None
b) Iteration Answer: b
c) Both
d) None Indirect recursion means:
Answer: c a) Method A calls itself
b) Method A calls Method B which calls Method A
Fibonacci series can be implemented using: c) Both A and B call themselves
a) Recursion d) None
b) Iteration Answer: b
c) Both
d) None Recursion is mostly used when:
Answer: c a) Problem can be broken into smaller sub-problems
b) Problem is linear
Tower of Hanoi problem is solved using: c) Arrays are involved
a) Loop d) Loops are avoided
b) Recursion Answer: a
c) Both
d) None Part C: String Manipulation (Q36–Q50)
Answer: b
String in Java is:
In recursion, each method call is stored in: a) Mutable
a) Heap b) Immutable
b) Stack c) Static
c) Queue d) Dynamic
d) Array Answer: b
Answer: b
Which class is used for mutable strings?
Which is faster generally? a) String
a) Recursion b) StringBuffer
c) StringBuilder
d) Both b and c Which method replaces characters in a string?
Answer: d a) change()
b) replace()
Which method gives length of a string? c) modify()
a) length d) update()
b) size() Answer: b
c) length()
d) count() Which method checks if string starts with given prefix?
Answer: c a) beginsWith()
b) startsWith()
Which method returns character at an index? c) firstWith()
a) charAt() d) checkStart()
b) getChar() Answer: b
c) char()
d) substring() Which method checks if string ends with given suffix?
Answer: a a) endWith()
b) lastWith()
Index of first character in string is: c) endsWith()
a) 1 d) checkEnd()
b) 0 Answer: c
c) -1
d) Depends Which method returns index of first occurrence of
Answer: b substring?
a) indexOf()
Which method is used to convert to uppercase? b) position()
a) upper() c) find()
b) toUpperCase() d) locate()
c) caseUpper() Answer: a
d) upperCase()
Answer: b
Which method is used to convert to lowercase?
a) lower()
b) toLowerCase()
c) caseLower()
d) lowCase()
Answer: b
Which method checks equality of two strings?
a) ==
b) equals()
c) compare()
d) match()
Answer: b
Which method compares lexicographically?
a) compareTo()
b) equals()
c) match()
d) compare()
Answer: a
Which method extracts part of a string?
a) substring()
b) sub()
c) slice()
d) cut()
Answer: a
Which method removes spaces from both ends?
a) trim()
b) strip()
c) cut()
d) remove()
Answer: a