TCS Technical Interview Questions - Detailed Answers
1. Programming Languages (Java, C, Python)
Q1. What is the difference between C and Java?
C is a procedural programming language, meaning that it follows a top-down approach and
programs are organized as a set of functions. It offers low-level memory access and is primarily
used for system programming, embedded systems, and performance-critical applications. Java, on
the other hand, is an object-oriented programming language. It uses a bottom-up approach and
organizes code into classes and objects. Java is platform-independent thanks to the Java Virtual
Machine (JVM), supports garbage collection, and is widely used in enterprise-level applications and
Android development.
Q2. What are the OOP principles in Java?
The four major principles of Object-Oriented Programming in Java are:
- Encapsulation: Wrapping of data (variables) and code (methods) into a single unit called a class. It
helps in data hiding and provides access control through private, public, and protected access
modifiers.
- Abstraction: Hides implementation details from the user and shows only functionality. Achieved
using abstract classes and interfaces.
- Inheritance: Mechanism by which one class (child) can acquire properties and behaviors (methods)
of another class (parent). Promotes code reuse.
- Polymorphism: The ability of an object to take many forms. Achieved through method overloading
(compile-time) and method overriding (runtime).
Q3. Difference between == and .equals() in Java?
- The ==' operator checks whether two object references point to the same memory location.
- The .equals() method is used to compare the contents of two objects. For example, in String
comparison, .equals() compares character sequences.
Q4. What is a constructor in Java?
A constructor is a special method that is automatically called when an object is created. It has the
same name as the class and does not have a return type. Constructors are used to initialize objects.
There are two types: Default constructor (no parameters) and Parameterized constructor (accepts
arguments to initialize values).
Q5. Method Overloading vs Method Overriding
- Method Overloading: Same method name with different parameters within the same class. It
increases code readability.
- Method Overriding: A subclass provides a specific implementation of a method already defined in
the parent class. It allows dynamic method dispatch (runtime polymorphism).
(Continued in PDF...)