Hot Topics
TCS Solution
Technical Round
- Question 1
Explain any important feature of OOPs.
- Answer
Important features of OOPs are
Inheritance: It is a concept of Object Oriented Programming in which a new class is created from the existing one.
Polymorphism: Poly means many and morph means form. A concept that enables programmers to assign a different meaning or usage to a variable, function or an object in different context.
Polymorphism can be of two types:
Runtime Polymorphism
Compile Time Polymorphism
Abstraction: Creating a new data type using encapsulated items that is well suited for an application.
Encapsulation: It is called data hiding and encapsulation is the way of packing data and function into a single unit to hide the implementation details of a class from outer world.
Method Overriding: In place of inheritance if the parent class and child class both have the same method signature then child class method overrides the parent class method.
Method Overloading: If a class has more than one method with the same method name with variety of parameter list then method will be overloaded.
Object: Object is the reality of a class.
Class: Class is a blue print of similar type of objects.
Constructor: Constructor is a special member function that is automatically invoked at the time of object creation and does not have any return type.
- Question 2
Write a program to fetch first 10 even natural numbers.
- Answer
#include<stdio.h>
int main() {
for(int i=2;i<=20;i+=2){
printf("%d\n",i);
}
return 0;
}
/*
OUTPUT:
2 4 6 8 10 12 14 16 18 20
*/
- Question 3
Which programming language you most familiar with?
- Answer
You should mention the programming language that you are most familiar with because interviewer will ask you from your familiar programming language.
- Question 4
What are the four pillars of OOPs?
- Answer
Four pillars of OOPs are:
Abstraction
Encapsulation
Inheritance
Polymorphism
- Question 5
1) Esha ran 224m in 27 sec and Usha in 17 sec. At what distance did Esha cross Usha?
2) A series 1234123441234441234444…..n what is the value on 200th position..?
3)Star mark question: How many squares are there between 2011 to 2300 which follows 2013,2020,2027…….2300
- Answer
Without additional information, it is not possible to determine at what distance Esha and Usha crossed each other.
The value on 200th position in the given series is 4.
There are 45 squares between 2011 and 2300 that follow the pattern 2013, 2020, 2027, …, 2300.
- Question 6
What are the steps to connect to a database?
- Answer
To connect a database with a Java program:
Import packages
Register the driver class
Create connection with connection class object
Create statement
Execute the query
Close connections
- Question 7
Write a query to find second highest salary.
- Answer
SELECT name, MAX(salary) AS salary FROM employee WHERE salary <> (SELECT MAX(salary) FROM employee);
OR
Common Table Expression
WITH T AS ( SELECT * DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk FROM Employees) SELECT Name FROM T WHERE Rnk=2;
- Question 8
Is String immutable?
- Answer
String is immutable in Java which means string can’t be modified or changed. It is immutable because if it is mutable then there will be a high security lapse by changing the reference value of the input.
- Question 9
What is encapsulation?
- Answer
Encapsulation is the method to hide the data in a single entity by
protecting information from outside classes. Encapsulation can be
obtained by using of access modifiers such as public, private, protected
& default.
- Question 10
Explain inheritance.
- Answer
Inheritance is a mechanism in which an object acquires properties from its parent object.
- Question 11
Is Java really platform independent?
- Answer
Java is really platform independent language because of its bytecodes that can run on any system irrespective of its operating system.
- Question 12
Two candles, different densities, each burns for exactly 30 minutes. how do u measure 45 minutes.
- Answer
We can first burn a candle from one side which will take 30minutes to burn. For the second candle we can start burning it from both the sides. This way we can calculate extra 15minutes to burn the candle. By adding both the time of burning candle we can calculate 45 minutes.
- Question 13
Write a program for Fibonacci series.
- Answer
#include<stdio.h>
int main()
{
int x=0,y=1,z,i;
for(i=1;i<=10;i++)
{
printf(" %d",x);
z=x+y;
x=y;
y=z;
}
return 0;
}
/*
OUTPUT
0 1 1 2 3 5 8 13 21 34
*/
- Question 14
Tell 3 java collections classes.
- Answer
- Question 15
Write a for loop program to print a line 10 times.
- Answer
#include<stdio.h>
int main()
{
int n;
printf("Enter the number of times you want to print lines\n");
scanf("%d",&n);
for(int i=1;i<=n;i++){
printf("Line number %d\n",i);
}
return 0;
}
/*
INPUT:
n=10
OUTPUT
Line number 1
Line number 2
Line number 3
Line number 4
Line number 5
Line number 6
Line number 7
Line number 8
Line number 9
Line number 10
*/
- Question 16
What was the real life example of polymorphism?
- Answer
A person can have different relationships with different people.
- Question 17
What is an array?
- Answer
An array is a linear data structure that can store same data types in
contiguous memory allocation..
- Question 18
Give algorithm for factorial of c program?
- Answer
Take an integer from the user to find the factorial
Read the integer and assign it to a variable
From the value of the integer up to 1, multiply each digit and update the final value
The final value at the end of all the multiplication till 1 is the factorial