Java 8 | OOP | SQL | Programming Logic
Duration: 20 Minutes
Experience: 2–6 Years
This assessment is intended for a quick technical screening of Java Backend Developers before proceeding to detailed technical interviews.
Skills Tested:
- OOPS
- Overloading & Overriding
- Static methods
- Java 8 Functional Interfaces
- Exception Handling
- SQL
- Programming Logic
Section A – Java OCP Style MCQs (5 Questions)
Question 1 – Static Method Hiding
What is the output?
class Parent {
static void print() {
System.out.print("Parent ");
}
}
class Child extends Parent {
static void print() {
System.out.print("Child ");
}
}
public class Test {
public static void main(String[] args) {
Parent p = new Child();
p.print();
}
}
A. Parent
B. Child
C. Parent Child
D. Compilation Error
Question 2 – Method Overloading
public class Test {
static void display(Object obj){
System.out.print("Object ");
}
static void display(String str){
System.out.print("String ");
}
public static void main(String[] args){
display(null);
}
}
Output?
A. Object
B. String
C. Compilation Error
D. NullPointerException
Question 3 – Method Overriding
class Animal {
void sound(){
System.out.print("Animal ");
}
}
class Dog extends Animal{
void sound(){
System.out.print("Dog ");
}
}
public class Test{
public static void main(String[] args){
Animal a=new Dog();
a.sound();
}
}
A. Animal
B. Dog
C. Compilation Error
D. Runtime Exception
Question 4 – Functional Interface
@FunctionalInterface
interface Operation{
int calculate(int a,int b);
}
public class Test{
public static void main(String[] args){
Operation op=(a,b)->a*b;
System.out.println(op.calculate(4,5));
}
}
Output?
A. 9
B. 20
C. Compilation Error
D. Runtime Exception
Question 5 – Exception Handling
public class Test{
public static void main(String[] args){
try{
System.out.print("A ");
throw new RuntimeException();
}
catch(Exception e){
System.out.print("B ");
}
finally{
System.out.print("C");
}
}
}
Output?
A. A B C
B. A C
C. B C
D. RuntimeException
Section B – SQL (1 Question)
Question 6
Table:
| EMP_ID | NAME | DEPT | SALARY |
|---|---|---|---|
| 1 | John | IT | 5000 |
| 2 | Mary | HR | 6000 |
| 3 | Steve | IT | 7000 |
| 4 | David | HR | 4000 |
| 5 | Tom | IT | 5500 |
Query
SELECT DEPT,
COUNT(*)
FROM EMPLOYEE
GROUP BY DEPT
HAVING AVG(SALARY)>5500;
Output?
A.
IT 3
B.
HR 2
C.
IT 3
HR 2
D.
No Rows
Section C – Programming (3 Questions)
Question 7 – String Logic
Write a Java program to check whether two strings are anagrams.
Example
listen
silent
Output
true
Question 8 – Collections & Java 8
Given
List<Integer> list =
Arrays.asList(2,5,8,3,4,2,8);
Using Java 8 (preferred), write a program to:
- Remove duplicates
- Print only even numbers
- Sort in descending order
Expected Output
8
4
2
Question 9 – Programming Logic
Write a Java program to reverse every word in the sentence while preserving the word order.
Example
Java Backend Interview
Expected Output
avaJ dnekcaB weivretnI
Bonus: Solve without using StringBuffer.reverse().
Answer Key
| Q | Answer |
|---|---|
| 1 | A |
| 2 | B |
| 3 | B |
| 4 | B |
| 5 | A |
| 6 | A |
Evaluation Guide
| Score | Rating |
|---|---|
| 9/9 | Excellent – Strong Java 8 Developer |
| 7–8 | Good – Recommended for Technical Round |
| 5–6 | Average – Needs Deeper Evaluation |
| Below 5 | Not Recommended |
Answer Key & Detailed Explanations
Section A – Java OCP Style MCQs
Question 1 – Static Method Hiding
Correct Answer: A. Parent
Explanation
Parent p = new Child();
p.print();
Static methods are hidden, not overridden.
The method that executes depends on the reference type, not the object type.
Since p is of type Parent, Parent.print() is called.
Key Concept: Static methods are resolved at compile time.
Question 2 – Method Overloading
Correct Answer: B. String
Explanation
The compiler finds two overloaded methods:
display(Object obj)
display(String str)
When null is passed, both methods are applicable.
Java always selects the most specific overload, which is String.
Key Concept: Overloading is resolved at compile time.
Question 3 – Method Overriding
Correct Answer: B. Dog
Explanation
Animal a = new Dog();
a.sound();
This is runtime polymorphism.
Although the reference is Animal, the actual object is Dog, therefore Java invokes:
Dog.sound()
Key Concept: Overridden instance methods are resolved at runtime.
Question 4 – Functional Interface
Correct Answer: B. 20
Explanation
The lambda expression
(a,b) -> a * b
implements the single abstract method of the functional interface.
4 × 5 = 20
Output:
20
Key Concept: A Functional Interface contains exactly one abstract method and can be implemented using a lambda expression.
Question 5 – Exception Handling
Correct Answer: A. A B C
Explanation
Execution sequence:
try
↓
Print A
↓
Throw RuntimeException
↓
catch
↓
Print B
↓
finally
↓
Print C
Output
A B C
Key Concept: The finally block executes whether or not an exception occurs (except in a few JVM termination scenarios).
Section B – SQL
Question 6
Correct Answer: A
Query
SELECT DEPT,
COUNT(*)
FROM EMPLOYEE
GROUP BY DEPT
HAVING AVG(SALARY) > 5500;
Step 1 – Group Data
| Department | Employees | Average Salary |
|---|---|---|
| IT | 5000,7000,5500 | 5833.33 |
| HR | 6000,4000 | 5000 |
Step 2 – Apply HAVING
5833 > 5500 ✓
5000 > 5500 ✗
Only IT satisfies the condition.
Output
IT 3
Interview Concepts Tested
- GROUP BY
- Aggregate Functions
- HAVING clause
- SQL execution order
Execution order:
FROM
GROUP BY
HAVING
SELECT
Section C – Programming Questions
Question 7 – Anagram
Sample Solution (Java 8)
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String s1 = "listen";
String s2 = "silent";
char[] a = s1.toCharArray();
char[] b = s2.toCharArray();
Arrays.sort(a);
Arrays.sort(b);
System.out.println(Arrays.equals(a, b));
}
}
Output
true
Alternate Approach
- Use
HashMap<Character,Integer> - Count frequency of every character
Complexity
Time: O(n log n)
Space: O(n)
Question 8 – Collections & Java 8
Sample Solution
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Arrays.asList(2,5,8,3,4,2,8)
.stream()
.distinct()
.filter(n -> n % 2 == 0)
.sorted((a,b) -> b-a)
.forEach(System.out::println);
}
}
Output
8
4
2
Java 8 Concepts Tested
- Streams
- distinct()
- filter()
- sorted()
- Lambda Expressions
- Method References
Complexity
Time: O(n log n)
Space: O(n)
Question 9 – Reverse Every Word
Sample Solution
public class Test {
public static void main(String[] args) {
String input = "Java Backend Interview";
String[] words = input.split(" ");
for(String word : words){
for(int i = word.length()-1; i >= 0; i--){
System.out.print(word.charAt(i));
}
System.out.print(" ");
}
}
}
Output
avaJ dnekcaB weivretnI
Bonus Java 8 Solution
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String input = "Java Backend Interview";
Arrays.stream(input.split(" "))
.map(s -> new StringBuilder(s)
.reverse()
.toString())
.forEach(s -> System.out.print(s + " "));
}
}
Complexity
Time: O(n)
Space: O(n)
Interview Evaluation Notes
Candidates who answer correctly should be able to explain why, not just provide the output.
| Question | Skill Being Tested |
|---|---|
| Q1 | Static method hiding vs overriding |
| Q2 | Method overloading resolution |
| Q3 | Runtime polymorphism |
| Q4 | Functional Interface & Lambda |
| Q5 | Exception handling and finally block |
| Q6 | SQL execution order, GROUP BY, HAVING |
| Q7 | String manipulation, Arrays, Algorithm |
| Q8 | Collections, Streams, Lambda, Sorting |
| Q9 | Loops, Strings, Java 8 thinking |
Scoring Rubric
| Score | Recommendation |
|---|---|
| 9/9 | Excellent. Strong Java developer with good problem-solving ability. |
| 7–8 | Good. Suitable for the next technical round. |
| 5–6 | Average. Understands fundamentals but needs deeper evaluation. |
| Below 5 | Significant gaps in Java fundamentals; not recommended for backend Java roles. |