new vritusa questions Concept of singleton class
About Private constrictor
some code snippets
Hashing in java
threading ( i didn't know about it then)
what do you mean by public static void main in java
overloading vs overriding
abstract class vs interface
access modifiers
exceptional handling
inheritance and it's types
polymorphism and other oops concepts
Sql query to update the bus no
one other basic sql query which currently I'm not able to
remember
Array list and collection framework
wrtire ans in interview focused okay with reqquired
codes
Below are clean, interview-focused answers to all Virtusa-related Java + SQL + OOP
questions — short, crisp, and with sample code.
Exactly how you should answer in a real interview.
✅ 1. Concept of Singleton Class
A Singleton class allows only one object of the class to be created in the entire
application.
Why used?
Logging
Database connection
Configuration management
Code (Best: Lazy Initialization + Thread Safe)
java Copy code
class Singleton {
private static Singleton instance;
private Singleton() {} // private constructor
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
✅ 2. Private Constructor
A constructor is made private to restrict object creation from outside the class.
Where used?
Singleton Pattern
Utility classes (all methods static)
Example:
java Copy code
class Utility {
private Utility() {} // no object creation allowed
public static void show() {
[Link]("Utility Method");
}
}
✅ 3. Hashing in Java
Hashing is a technique to convert data into a hash code, used for fast searching.
Where used?
HashMap
HashSet
HashTable
How it works?
1. Key → hashCode()
2. Bucket index = hashCode % arraySize
3. Collision handled by LinkedList/Tree (Java 8+ → balanced tree)
Example:
java Copy code
Map<String, Integer> map = new HashMap<>();
[Link]("prem", 1);
[Link]("rahul", 2);
✅ 4. Threading (Simple Explanation)
A thread is the smallest unit of execution. It provides multitasking.
Ways to create a thread:
1. Extending Thread class
java Copy code
class MyThread extends Thread {
public void run() {
[Link]("Thread running");
}
}
new MyThread().start();
2. Implementing Runnable
java Copy code
class Task implements Runnable {
public void run() {
[Link]("Runnable running");
}
}
new Thread(new Task()).start();
✅ 5. Meaning of public static void main(String[]
args)
public → accessible by JVM
static → no object required
void → no return type
main → program execution starts here
String[] args → command-line arguments
✅ 6. Overloading vs Overriding
Method Overloading
Same method name
Different parameters
Compile-time polymorphism
java Copy code
int add(int a, int b) {}
int add(int a, int b, int c) {}
Method Overriding
Same method name & signature
Child modifies parent method
Runtime polymorphism
java Copy code
class A { void show() {} }
class B extends A { void show() {} }
✅ 7. Abstract Class vs Interface
Abstract Class
Can have abstract + normal methods
Can have constructor
Supports single inheritance
Use when classes are related
Interface
Only abstract methods (Java 7)
Default + static + private methods (Java 8+)
No constructors
Multiple inheritance
Example:
java Copy code
abstract class Animal {
abstract void eat();
}
interface Flyable {
void fly();
}
✅ 8. Access Modifiers
Modifier Visibility
public everywhere
protected same package + child class
default same package only
private same class only
✅ 9. Exception Handling
Used to handle runtime errors gracefully.
Example:
java Copy code
try {
int a = 10 / 0;
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
} finally {
[Link]("Always runs");
}
Types:
Checked (IOException, SQLException)
Unchecked (NullPointerException, ArithmeticException)
✅ 10. Inheritance & Its Types
Inheritance → acquiring properties of parent class.
Types in Java:
1. Single
2. Multilevel
3. Hierarchical
(Multiple inheritance not allowed via class, allowed via Interface)
java Copy code
class A {}
class B extends A {} // Single
class C extends B {} // Multilevel
✅ 11. Polymorphism
Polymorphism → many forms.
Types:
1. Compile time → Overloading
2. Runtime → Overriding
✅ 12. SQL Query to Update Bus Number
sql Copy code
UPDATE bus_table
SET bus_no = 'MH12AB1234'
WHERE bus_id = 5;
✅ 13. Another Basic SQL Query (Select with Condition)
sql Copy code
SELECT name, bus_no
FROM bus_table
WHERE bus_no LIKE 'MH12%';
✅ 14. ArrayList & Collection Framework
Collection Framework
A set of interfaces & classes to store and manipulate data.
Main interfaces:
List
Set
Map
Queue
ArrayList Example:
java Copy code
ArrayList<String> list = new ArrayList<>();
[Link]("prem");
[Link]("rahul");
for (String s : list) {
[Link](s);
}
✅ If you want, I can also prepare:
✔ Quick revision PDF
✔ Mock interview questions
✔ Coding rounds (Java + SQL for Virtusa)
Just tell me “send mock questions” or “make pdf”.
2/2
Basic functionality of my project
Difference between abstract class and interface
Difference between union and unionAll
We can use printf() apart from just printing values, if yes
then where?
Difference between checked and unchecked error?
What if we directly use run method to start a thread?
What is different in extend Thread class and implement
Runnable interface?
SDLC Model and its type
Difference between left join and right join
Below are interview-focused, crisp answers for each question — the way you should
answer in Virtusa’s face-to-face round.
✅ 1. Basic Functionality of My Project (LearnifyPro /
BrainwaveAI / Portfolio)
(Use this script — short, clear, technical)
LearnifyPro (LMS) – Basic Functionality
It is a Learning Management System with Admin + User Panel.
Admin can create/update/delete courses, manage students, track progress.
Students can enroll in courses, watch videos, attempt quizzes, and track
performance.
Implemented role-based authentication, payment flow, and real-time notifications
using [Link].
Backend handles CRUD operations, caching with Redis, secure APIs.
Optimized performance with MongoDB indexes & clean architecture.
Brainwave AI – Basic Functionality
AI-powered system to save ideas, bookmarks, notes, contacts.
User can search, organize, chat with collections, use a Chrome extension.
Uses vector embeddings for semantic search, D1 DB + Cloudflare workers.
(Use whichever project you want — this is interviewer style.)
✅ 2. Difference Between Abstract Class and Interface
Abstract Class
Can have abstract + non-abstract methods
Can have constructors, variables, blocks
Supports single inheritance
Used when classes share a common structure
Interface
Only abstract methods (till Java 7)
From Java 8 → default, static methods allowed
No constructors
Supports multiple inheritance
Used to define capabilities/behaviors
✅ 3. Difference Between UNION and UNION ALL
Feature UNION UNION ALL
Removes duplicates ✔ Yes ❌ No
Performance Slower (because of DISTINCT) Faster
Feature UNION UNION ALL
Output rows Unique rows only All rows including duplicates
Example
sql Copy code
SELECT name FROM tableA
UNION
SELECT name FROM tableB;
sql Copy code
SELECT name FROM tableA
UNION ALL
SELECT name FROM tableB;
✅ 4. Can printf() Be Used Apart from Printing Values?
Yes.
printf() can be used for formatted output → especially useful when you:
Align output
Print tables
Format numbers (decimal places)
Format strings (padding, alignment)
Example:
java Copy code
[Link]("Name: %s | Age: %d%n", "Prem", 25);
[Link]("Salary: %.2f", 52000.567);
✅ 5. Difference Between Checked and Unchecked
Errors/Exceptions
Checked Exceptions
Checked at compile-time
Must be handled using try-catch or throws
Examples: IOException, SQLException
Unchecked Exceptions
Occur at runtime
Not checked by compiler
Examples: NullPointerException, ArithmeticException
✅ 6. What Happens If We Directly Use run() Instead of
start()?
Calling run() → runs in the same thread, no multithreading happens.
Calling start() → creates a new thread, then internally calls run().
Example:
java Copy code
Thread t = new Thread();
[Link](); // new thread
[Link](); // normal method call, NOT a new thread
✅ 7. Difference Between Extending Thread Class vs
Implementing Runnable
Extending Thread
Class cannot extend another class (single inheritance issue)
You directly override run()
Used when you want to modify Thread class behavior
Implementing Runnable
Better and widely used approach
Allows multiple inheritance (class can extend another class also)
Runnable object is passed to Thread class
Example:
java Copy code
class A implements Runnable {
public void run() {}
}
new Thread(new A()).start();
✅ 8. SDLC Model and Its Types
SDLC (Software Development Life Cycle) is the process used to develop high-quality
software.
Phases
1. Requirement Gathering
2. Analysis
3. Design
4. Development
5. Testing
6. Deployment
7. Maintenance
Types of SDLC Models
Waterfall Model
Agile Model (Scrum)
V-Model
Iterative Model
Spiral Model
Big Bang Model
For Virtusa (Agile company), best answer:
👉 “Most companies including Virtusa follow Agile/Scrum – short sprints, frequent
releases, continuous feedback.”
✅ 9. Difference Between LEFT JOIN and RIGHT JOIN
LEFT JOIN
Returns:
All rows from left table
Matching rows from right table
Unmatched → NULL
sql Copy code
SELECT *
FROM A
LEFT JOIN B ON [Link] = [Link];
RIGHT JOIN
Returns:
All rows from right table
Matching rows from left
Unmatched → NULL
sql Copy code
SELECT *
FROM A
RIGHT JOIN B ON [Link] = [Link];
🚀 Want me to prepare:
✔ Mock interview Q&A
✔ Java coding round preparation
✔ A 1-page crisp revision sheet for Virtusa
Just say “send revision sheet” or “send mock questions”.
How many words can be read by cin?
What is the use of ‘super’ keyword inside a constructor?
Explain the concept of proper inheritance?
What are abstract classes and anonymous classes?
When should a function throw an exception?
Below are crisp, interview-focused answers — exactly how you should respond in a
technical F2F round.
✅ 1. How many words can be read by cin ?
cin (C++) using the extraction operator ( >> ) reads only one word at a time, i.e., it
stops reading input when it encounters a:
Space
Tab
Newline
Example:
cpp Copy code
string s;
cin >> s; // reads only first word
If the input is:
“Prem Shinde Virtusa”
cin >> s → reads only "Prem"
To read a full sentence → use getline(cin, s);
✅ 2. What is the use of super keyword inside a
constructor?
super() is used to:
✔ Call the parent class constructor
✔ Initialize the base class variables
✔ Avoid code duplication
✔ Ensure parent part of the object is created first
Example:
java Copy code
class Parent {
Parent(int a) { }
}
class Child extends Parent {
Child() {
super(10); // calls Parent(int) constructor
}
}
Java automatically adds super() if you don’t write it.
✅ 3. Explain the concept of “Proper Inheritance”?
Proper Inheritance means:
✔ A child class must logically extend the parent class
✔ The relationship should follow “IS-A” rule
✔ Avoid misuse of inheritance just for reusing code
✔ Maintain clean hierarchy and avoid deep inheritance chains
Good Example:
Car extends Vehicle → Car is a Vehicle
Bad Example:
Car extends Person → Wrong relationship
Proper inheritance ensures:
Reusability
Maintainability
Correct OOP design
Liskov Substitution Principle (LSP)
✅ 4. What are Abstract Classes and Anonymous Classes?
Abstract Class
Cannot be instantiated
Can have abstract + normal methods
Used to provide a base/template for subclasses
java Copy code
abstract class Animal {
abstract void sound();
}
Anonymous Class
A class without a name, created for immediate use — usually to provide one-time
implementation of an interface or abstract class.
Example:
java Copy code
Animal dog = new Animal() {
void sound() {
[Link]("Bark");
}
};
Used when:
You need a quick, temporary implementation
Don’t want to create a separate class file
✅ 5. When should a function throw an exception?
A function should throw an exception when:
✔ An error occurs that it cannot handle internally
✔ A failure breaks the normal flow
✔ Input is invalid
✔ Required resource is missing (file, db connection, etc.)
✔ Operation produces an unexpected state
Example:
java Copy code
int divide(int a, int b) {
if (b == 0) {
throw new ArithmeticException("Division by zero");
}
return a / b;
}
Exceptions should be thrown when:
Error is exceptional, not regular
Caller should decide how to recover
🚀 If you want, I can prepare a full Virtusa interview sheet
including C++, Java, SQL, OOP, HR questions.
How can you insert values in multiple rows using one
Insert statement?
Explain access specifiers?
What are TCP/IP protocols?
What are near, far and huge pointers?
Explain waterfall model?
Below are crisp, interview-focused answers exactly in the style useful for Virtusa F2F
technical rounds.
✅ 1. How can you insert values in multiple rows using
one INSERT statement?
You can use a single INSERT with multiple value sets:
SQL (MySQL, PostgreSQL, SQL Server):
sql Copy code
INSERT INTO students (id, name, age)
VALUES
(1, 'Prem', 21),
(2, 'Rahul', 22),
(3, 'Riya', 23);
This will insert 3 rows in one statement.
Oracle (older versions)
sql Copy code
INSERT ALL
INTO students (id, name, age) VALUES (1, 'Prem', 21)
INTO students (id, name, age) VALUES (2, 'Rahul', 22)
INTO students (id, name, age) VALUES (3, 'Riya', 23)
SELECT * FROM dual;
✅ 2. Explain Access Specifiers (Java)
Access specifiers define visibility of classes, methods, and variables.
Specifier Visibility Used Where?
public Accessible everywhere For APIs, classes used globally
protected Same package + subclasses For inheritance
default (no keyword) Same package only Package-level access
private Within same class only Data hiding, encapsulation
Simple Example:
py
java
public class A {
private int x; // only inside A
protected int y; // A, same package, child classes
int z; // default → same package
public int w; // anywhere
}
✅ 3. What are TCP/IP Protocols?
TCP/IP is a suite of communication protocols used for networking and the Internet.
Major Protocols:
1. TCP (Transmission Control Protocol)
Connection-oriented
Reliable
Ensures delivery, ordering, retransmission
Used in: web browsing, email, file transfer
2. IP (Internet Protocol)
Handles addressing and routing
Delivers packets across networks
3. HTTP/HTTPS
Application layer
Used for web communication
4. FTP
File transfer protocol
5. SMTP
Email sending
6. DNS
Converts domain name → IP address
7. UDP
Connectionless
Faster, no reliability
Used in video streaming, games
✅ 4. What are near, far, and huge pointers?
(Asked in C/C++ interviews related to memory models)
These existed in old 16-bit compilers (Turbo C).
✔ Near Pointer
16-bit pointer
Can access 64 KB segment
Faster
Small memory range
✔ Far Pointer
32-bit pointer
Can access different memory segments
Can access the entire 1 MB memory
Slower than near pointers
✔ Huge Pointer
Also 32-bit
Segment:offset normalized
Allows pointer arithmetic beyond 64 KB limit
👉 Modern compilers (32-bit/64-bit GCC, Clang, MSVC) do not use these pointer types.
✅ 5. Explain Waterfall Model
Waterfall Model is a linear, sequential SDLC model.
It flows step-by-step downward like a waterfall.
Phases:
1. Requirement Gathering
2. System Design
3. Implementation/Development
4. Testing
5. Deployment
6. Maintenance
Key Points:
Next phase starts only after previous phase completes
No going back
Good for small, clearly defined projects
Not suitable for changing requirements
Real Use:
Banking
Government projects
Defense systems
(Where requirements don't change)
⚡ Want me to prepare a complete revision sheet for
your Virtusa interview (1 page, crisp)?
/Difference between Linked list and Queue?
What are bitfields? What is the use of bit fields in a
Structure declaration?
Write an algorithm for quick sort?
What is cursor?
Difference between rowid and rownum in SQL?
Below are crisp, interview-focused answers (perfect for Virtusa F2F technical round).
✅ 1. Difference between Linked List and Queue
Feature Linked List Queue
Definition A linear data structure where Follows FIFO (First In, First Out)
elements are stored in nodes with
pointers
Purpose General-purpose list Task scheduling, order processing
Operations Insert/delete anywhere Enqueue (rear), Dequeue (front)
Implementation Can be Singly/ Doubly linked Usually implemented using LinkedList
or Array
Order No fixed discipline Strict FIFO
Example in Java LinkedList class Queue , PriorityQueue , ArrayDeque
Example (Java conceptual uses):
LinkedList → dynamic list, add/remove anywhere
Queue → scheduling, order, printing jobs
✅ 2. What are Bitfields? What is their use in structures?
(C)
Bitfields allow you to store data in bits instead of full bytes inside a structure.
Why used?
To save memory
Used in embedded systems, device registers, flags, protocol packets
Example:
c Copy code
struct Status {
unsigned int error : 1;
unsigned int ready : 1;
unsigned int mode : 2;
};
Meaning:
error uses 1 bit
ready uses 1 bit
mode uses 2 bits
Total = 4 bits, not 4 bytes
✅ 3. Write Algorithm for Quick Sort
Quick Sort Algorithm
scss Copy code
QuickSort(arr, low, high):
if low < high:
pivotIndex = Partition(arr, low, high)
QuickSort(arr, low, pivotIndex - 1)
QuickSort(arr, pivotIndex + 1, high)
Partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j from low to high - 1:
if arr[j] < pivot:
i = i + 1
swap arr[i] with arr[j]
swap arr[i + 1] with arr[high]
return i + 1
Time Complexity:
Best: O(n log n)
Worst: O(n²)
In-place sorting, uses divide & conquer
✅ 4. What is a Cursor?
A cursor is a database pointer used to fetch rows one-by-one from a result set.
Used when:
Row-by-row processing is needed
Complex database operations
Stored procedures, triggers
Types:
Implicit cursor (automatically created)
Explicit cursor (manually declared by programmer)
Example (Oracle):
sql Copy code
DECLARE
CURSOR c IS SELECT * FROM employees;
BEGIN
OPEN c;
FETCH c INTO ...
CLOSE c;
END;
✅ 5. Difference between ROWID and ROWNUM (Oracle
SQL)
Feature ROWID ROWNUM
Meaning Physical address of a row in Temporary sequence number assigned to
memory rows
Unique ✔ Unique for each row ❌ Not unique
Constant ✔ Does not change unless ❌ Changes when query changes
row moves
Purpose Fast access, indexing Pagination, filtering
Format Hexadecimal string Simple integer
Example:
sql Copy code
SELECT ROWID, name FROM employees;
sql Copy code
SELECT ROWNUM, name FROM employees WHERE ROWNUM <= 5;
⚡ Want me to prepare a one-page final revision sheet
for Virtusa interview?
Difference between operator overloading and function
overloading
Can you instantiate an abstract class and what is an inner
class?
When do you call copy constructor?
How can you swap values between two rows in a table
using single- SQL statement?
What is the type of this pointer?
Alright Prem, here are crisp, interview-ready answers for all your remaining questions —
short, sharp, and perfect for Virtusa’s F2F round.
✅ 1. Difference Between Operator Overloading and
Function Overloading
Feature Operator Overloading Function Overloading
Meaning Giving new meaning to an Same function name, different
operator parameters
Used In C++, not in Java C++, Java
Purpose Makes objects work with + , - , Compile-time polymorphism
== , etc.
Feature Operator Overloading Function Overloading
Syntax operator+() , operator==() void fun(int) , void fun(double)
Example (C++ Operator Overloading)
cpp Copy code
class A {
public:
int x;
A(int x) : x(x) {}
A operator+(A obj) {
return A(x + obj.x);
}
};
Example (Function Overloading)
cpp Copy code
void add(int a, int b) {}
void add(double a, double b) {}
✅ 2. Can You Instantiate an Abstract Class? What is an
Inner Class?
Can you instantiate an abstract class?
❌ No, abstract classes cannot be instantiated directly.
But you can create objects using:
✔ A subclass
✔ An anonymous class
Example:
java Copy code
Animal a = new Animal() {
void sound() { [Link]("Bark"); }
};
What is an Inner Class?
An inner class is a class defined inside another class.
Types:
Member inner class
Static inner class
Local inner class
Anonymous inner class
Example:
java Copy code
class Outer {
class Inner {
void show() {
[Link]("Inner class");
}
}
}
Inner class can access outer class members directly.
✅ 3. When Do You Call a Copy Constructor? (C++)
Copy constructor is called when:
1. Object is created from another object
cpp Copy code
A obj2 = obj1;
2. Object is passed by value to a function
3. Object is returned from a function
4. Compiler needs to make a temporary copy
Example:
cpp Copy code
A obj2(obj1); // copy constructor
✅ 4. How Can You Swap Values Between Two Rows
Using a Single SQL Statement?
Method 1: Using UPDATE With CASE
sql Copy code
UPDATE employees
SET salary = CASE id
WHEN 1 THEN (SELECT salary FROM employees WHERE id = 2)
WHEN 2 THEN (SELECT salary FROM employees WHERE id = 1)
END
WHERE id IN (1, 2);
Method 2: Using a Temp Variable (MySQL Only)
sql Copy code
UPDATE mytable t1
JOIN mytable t2
SET [Link] = [Link],
[Link] = [Link];
Method 3: Using a Single UPDATE With JOIN
sql Copy code
UPDATE table_name a
JOIN table_name b ON [Link] = 1 AND [Link] = 2
SET [Link] = [Link],
[Link] = [Link];
✅ 5. What Is the Type of the this Pointer? (C++)
this pointer type is:
"C const"*
(“constant pointer to the current object”)
Meaning:
The pointer itself cannot be changed
But the object’s data can be modified
Example:
cpp Copy code
class A {
public:
void show() {
// here 'this' is of type A* const
}
};
⚡ Want me to compile all your Java + SQL + C/C++ +
OS + Networking Q&A into a single 4-page revision PDF?
1/2
Sure! First, they conducted a written coding test
where the question was about returning how many
subarrays in an array have an even sum. After
clearing that, I was shortlisted for an in-person
technical interview.
In the technical round, I first introduced myself. Then
the interviewer gave me a coding question on finding
the missing number in a sorted array. After that,
she asked a question related to customized errors,
where I explained the use of the throw keyword. The
final coding question was to write a simple program
using a MashMapl as well as give coding solutions
Below is a clear, interview-ready summary of your experience AND the exact coding
solutions for all the questions you mentioned (even-sum subarrays, missing number,
custom errors, HashMap program).
This is the BEST way to answer “Explain your interview experience” + show strong coding
understanding.
✅ Your Answer (Perfect to Tell in HR / Technical HR
Round)
**“The interview process had two stages. First, I appeared for a written coding round
where I solved a problem on finding how many subarrays have an even sum. I solved it
and got shortlisted for the technical interview.
In the face-to-face round, I started with my introduction. The interviewer first gave me a
problem to find the missing number in a sorted array. Then she asked about customized
errors and how the throw keyword works, which I explained with examples. The final task
was to write a small program using a HashMap .”**
✅ Now the Coding Solutions (short, clean, interview-
worthy)
1️⃣ Count Subarrays With Even Sum (Best O(n) Approach)
🔥 Trick:
If prefix sum is even, count of previous even prefix sums adds to answer
If prefix sum is odd, count of previous odd prefix sums adds to answer
Code:
java Copy code
int countEvenSumSubarrays(int[] arr) {
int prefix = 0, even = 1, odd = 0, count = 0;
for (int x : arr) {
prefix += x;
if (prefix % 2 == 0) {
count += even;
even++;
} else {
count += odd;
odd++;
}
}
return count;
}
Time Complexity → O(n)
Perfect for interviews.
2️⃣ Missing Number in a Sorted Array
Input Example:
1, 2, 3, 5, 6 → Missing = 4
✔ Approach 1: Simple (O(n))
java Copy code
int findMissing(int[] arr) {
for (int i = 0; i < [Link]; i++) {
if (arr[i] != i + 1)
return i + 1;
}
return -1;
}
✔ Approach 2: Binary Search (O(log n)) (Interview preferred)
java Copy code
int missingNumber(int[] arr) {
int low = 0, high = [Link] - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == mid + 1)
low = mid + 1;
else
high = mid - 1;
}
return low + 1;
}
3️⃣ Customized Errors → Using throw in Java
Concept:
throw is used to create a custom exception manually.
Example you should tell:
java Copy code
void checkAge(int age) {
if (age < 18) {
throw new IllegalArgumentException("Age must be 18+");
}
[Link]("Valid Age");
}
4️⃣ HashMap Program (Asked in your interview)
🔥 Simple Program:
java Copy code
import [Link].*;
public class HashMapExample {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
[Link]("Prem", 1);
[Link]("Rahul", 2);
[Link]("Riya", 3);
for ([Link]<String, Integer> e : [Link]()) {
[Link]([Link]() + " : " + [Link]());
}
}
}
Explain:
put() to add key-value
get() to fetch value
entrySet() to iterate
🌟 If you want, I can also prepare:
✔ Your full interview story (high-impact version)
✔ All the remaining theory answers you asked (operator overloading, copy constructor,
row swap SQL, etc.)
✔ A complete Virtusa technical revision sheet (Java + SQL + OS + Coding)
Just say “Send all remaining answers” and I’ll give the full set.
parent class of all classes in java
Perfect — I will answer each pending technical question, provide coding solutions (as
requested), and also respond to the last question: Parent class of all classes in Java.
All answers are interview-focused, short, crisp, and with examples.
✅ Difference between Operator Overloading and
Function Overloading
Operator Overloading Function Overloading
Same operator gives different meanings Same function name with different parameters
depending on operands
Operator Overloading Function Overloading
Supported in C++, not in Java Supported in Java and C++
Example: + used for int addition & string Example: add(int,int) & add(int,int,int)
concatenation
Example (C++ Operator Overloading)
cpp Copy code
Complex operator + (Complex c) {
return Complex(x + c.x, y + c.y);
}
Example (Function Overloading)
java Copy code
int add(int a, int b) {}
int add(int a, int b, int c) {}
✅ Can you instantiate an abstract class & What is an
Inner Class?
Can we instantiate an abstract class?
❌ No, we cannot create an object of an abstract class directly.
But we can create a reference of abstract class and object of subclass.
java Copy code
abstract class A {}
class B extends A {}
A obj = new B();
But using anonymous inner class, we can create an object-like implementation:
java Copy code
A obj = new A() {
void show() { [Link]("Hello"); }
};
Inner Class
A class defined inside another class.
Types:
Member inner class
Static inner class
Local inner class
Anonymous inner class
java Copy code
class Outer {
class Inner {
void display() {
[Link]("Inner class");
}
}
}
✅ When do you call Copy Constructor? (C++)
Copy constructor is called when:
Creating a new object from an existing object
Passing object by value
Returning an object
cpp Copy code
Test t1;
Test t2 = t1; // copy constructor call
✅ Swap values between two rows using one SQL
statement
Copy code
sql
UPDATE employees e1
JOIN employees e2
ON [Link] = 1 AND [Link] = 2
SET [Link] = [Link],
[Link] = [Link];
Or using a temp column:
sql Copy code
UPDATE tableName
SET col = col1, col1 = col
WHERE id IN (1,2);
✅ What is the type of this pointer?
In C++, this pointer is of type:
cpp Copy code
ClassName* const
Meaning: It is a constant pointer pointing to the current object.
In Java, this is a reference to the current object (not a pointer).
🧠 Coding Question Asked in Round
“Count subarrays with even sum”
java Copy code
public class EvenSubarrays {
public static int countEvenSum(int[] arr) {
int count = 0, sum = 0;
Map<Integer,Integer> map = new HashMap<>();
[Link](0, 1);
for (int num : arr) {
sum += num;
if ([Link](sum % 2)) {
count += [Link](sum % 2);
}
[Link](sum % 2, [Link](sum % 2, 0) + 1);
}
return count;
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4};
[Link](countEvenSum(arr)); // Output: 4
}
}
Missing Number in Sorted Array
java Copy code
int findMissing(int[] arr) {
for(int i=0; i<[Link]; i++) {
if(arr[i] != i+1) return i+1;
}
return -1;
}
🧠 Customized Error using throw
java Copy code
void validate(int age) {
if(age < 18) {
throw new ArithmeticException("Not Eligible");
}
}
🧠 HashMap Example
java
HashMap<Integer,String> map = new HashMap<>();
[Link](1,"Prem");
[Link](2,"Rahul");
[Link]([Link](1));
🎯 Parent Class of All Classes in Java
[Link] is the parent class of all classes in Java.
Every class implicitly extends Object class.
Example: