Technical Interview Questions and Answers :: Tech Mahindra
- Select All
- Java
- C++
- HR Question in TR
1 / 13
No Discussion on this question yet!
2 / 13
No Discussion on this question yet!
3 / 13
No Discussion on this question yet!
4 / 13
Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and exposing the functionality of any object. Encapsulation is the first step towards OOPS, is the procedure of covering up of data and functions into a single unit (called class). Its main aim is to protect the data from out side world.
5 / 13
No Discussion on this question yet!
6 / 13
No Discussion on this question yet!
7 / 13
No Discussion on this question yet!
8 / 13
1) Encapsulation: It is the mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls the access to that particular code and data.
2) Inheritance: It is the process by which one object acquires the properties of another object. This supports the hierarchical classification. Without the use of hierarchies, each object would need to define all its characteristics explicitly. However, by use of inheritance, an object need only define those qualities that make it unique within its class. It can inherit its general attributes from its parent. A new sub-class inherits all of the attributes of all of its ancestors.
3) Polymorphism: It is a feature that allows one interface to be used for general class of actions. The specific action is determined by the exact nature of the situation. In general polymorphism means "one interface, multiple methods"; this means that it is possible to design a generic interface to a group of related activities. This helps reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler's job to select the specific action (that is, method) as it applies to each situation.
9 / 13
A set is a collection that cannot contain duplicate elements. Set has it's implementation in various classes like HastSet, TreeSet, LinkedHashSet. Set has only methods that are inherited from Collection and adds the restrictions to prohibit duplicate elements.
10 / 13
Inheritance means, we use the methods or function or other public members of the parent class by child class. So to do this we have to extend the the parent class through it child class.
For Ex:- Amitabh bacchan's fames inherited by his child Abhishek.
Program Ex:-
class A{
print(){
System.out.println("HELLLO ");
}}
class B extends class A{
public static void main(String... args){
A pr=new A();
pr.print();
}}
Things to remember:---
* Every class in java inherited by its parent class Object which is in the package:- java.lang.Object when the class is not extended by any child class only.
* Java does not support "Multiple Inheritance" except in the case of Interface Concept.
Because one class cannot extend more than one class but Interface able to extend more than one.