Hot Topics
Capgemini Solution
Technical Round
- Question 1
What can you do to a method in a parent class so that it’s not overridden by a method in child class with same name?
- Answer
If we put a final keyword before the method then method overriding can be avoided.
- Question 2
Describe some real life applications of machine learning.
- Answer
Machine learning in real life can be used for
Image recognition
Speech recognition
Predictive analysis
- Question 3
What is static method?
- Answer
Static is keyword and by putting it in front of any method we do not need to create an object of the class to access the method.
- Question 4
Swap two numbers without using temp variable.
- Answer
#include <stdio.h>
int main() {
int a,b;
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
a=a-b;
b=a+b;
a=b-a;
printf("After swapping the value of a is:%d\n",a);
printf("After swapping the value of b is:%d",b);
return 0;
}
/*
INPUT:
Enter the value of a: 5
Enter the value of b: 4
OUTPUT:
After swapping the value of a is:4
After swapping the value of b is:5
*/
- Question 5
What is the use of pass in Python?
- Answer
In Python pass statement is used as a placeholder for the future code i.e. if we write a function and put pass in it then the code will be executed without giving an error.
- Question 6
What is an IP address?
- Answer
IP stands for internet protocol address which is a numeric value assigned to a network for identification and location of a network device. There are two types of IP:
Static IP
Dynamic IP
- Question 7
Write a code to determine if a string has duplicate characters.
- Answer
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool uniqueCharacters(char str[]);
int main() {
char str[] = "CodeWindow";
if (uniqueCharacters(str)) {
printf("String has no duplicate characters");
}
else {
printf("String has duplicate characters");
}
return 0;
}
bool uniqueCharacters(char str[])
{
for(int i=0;i<strlen(str);i++){
for (int j = i + 1; j < strlen(str); j++) {
if (str[i] == str[j]) {
return false;
}
}
}
return true;
}
/*
output:
String has duplicate characters
*/
- Question 8
A company has a share of 100 $. It went down by 20 %. Again it went down by 20%. How much increase in percentage is required to get back to 100$.
- Answer
If the company's share initially was 100 $ and it went down by 20%, then it is now at 100 - (100 * 20%) = 100 - 20 = 80 $.
Then, if the share went down by another 20%, it is now at 80 - (80 * 20%) = 80 - 16 = 64 $.
So, to get back to 100 $, the share price needs to increase by 100/64 - 1 = 56.25%.
- Question 9
What is OOPs inheritance and overloading?
- Answer
In Java OOPs inheritance is a concept of Object Oriented Programming in which a new class is created from the existing one. Overloading is achieved when we create multiple methods with the same name inside a single class and each method works differently.
- Question 10
What is <include> in C language and can we use something else instead of <> this angular bracket?
- Answer
<include> here means we are adding the code in the header file to the source code.
Yes we can use double quotation “ ” instead of <>.
- Question 11
What is the difference between String Builder and String Buffer?
- Answer
String Builder | String Buffer |
1. String Builder was introduced in Java 5 | String Buffer was introduced when Java program was launched |
2. It is not synchronized | It is synchronized |
3. String builder is faster than string buffer as it is not thread safe | String buffer is slower as it is thread safe i.e. it can’t access multiple threads at the same time |
- Question 12
Can we have static method in abstract class?
- Answer
Yes we can have static method in abstract class
- Question 13
What was your final year project?
- Answer
Tell your project topic & describe it.
- Question 14
What was your role in the project?
- Answer
Tell about your project role.
- Question 15
What is malloc() function?
- Answer
malloc function in C is used to dynamically allocate a single large block of memory with the specified size. It returns a pointer of type void which can be cast into a pointer of any form. It initializes each block with default garbage value.
- Question 16
What is the difference between interface and abstract class?
- Answer
Interface | Abstract class |
1. Interface supports the concept of multiple inheritance. | Abstract class doesn’t support the concept of multiple inheritance. |
2. Interface has only abstract methods. | Abstract class can have non-abstract method but it must have at least one abstract method. |
3. Interface keyword is used to declare interface | Abstract keyword is used to declare Abstract class. |
4. Interface has members as public by default. | Abstract class in Java can have private, protected, public and default class members. |
5. Interface supports multiple inheritance. | Abstract class does not support multiple inheritance. |
- Question 17
A SQL query to write tables and to join those tables by right and left joins.
- Answer
Here's an example of how you can write a SQL query to join two tables using both right and left join:
SELECT *
FROM table1
LEFT JOIN table2
ON table1.column1 = table2.column2
UNION
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.column1 = table2.column2;
- Question 18
How can you do dynamic memory allocation in C?
- Answer
In C programming language dynamic memory allocation can be done by using the following methods:
malloc() – It is also known as memory allocation. It is a method used in C to dynamically allocate a single large block of memory with the specified size.
Syntax: ptr = (caste_type*)malloc(byte size);
calloc() – It is also known as contiguous allocation. It is a method used in C to dynamically allocate the specified number of blocks of memory of the specified type.
Syntax: ptr= (caste_type*)calloc(n, ele_size);
realloc() – Modify the size of previously allocated space.
Syntax: ptr= realloc(ptr.newsize);
free() – free is previously allocated space.
Syntax: ptr=free(ptr);
- Question 19
The logic of Armstrong number program.
- Answer
A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if.
abcd… = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ….