Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers for 'Genpact' - 7 question(s) found - Order By Newest | ||||
Frequently asked in Infosys and HCL Technologies ( Based on 2 feedback ) | ||||
| ||||
Ans. Using new operator - new xyzClass() Using factory methods - xyzFactory.getInstance( ) Using newInstance( ) method - (Class.forName(xyzClass))emp.newInstance( ) By cloning an already available object - (xyzClass)obj1.clone( ) | ||||
Sample Code for object initialization using clone Sample Code for object initialization using getInstance | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   object creation   new operator   class.forname   cloning   ebay Asked in 9 Companies expert | ||||
| ||||
Ans. 1. Overriding method can not be more restrictive than the overridden method. reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method. If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic 2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access. 3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden. | ||||
Sample Code for Overriding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   overriding   access specifier   inheritence   oops   polymorphism  object oriented programming (oops)  oops concepts   runtime polymorphism  object oriented programming (oops)  oops concepts Asked in 4 Companies | ||||
Try 2 Question(s) Test | ||||
Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback) | ||||
| ||||
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashcode   advanced  hashtable Asked in 33 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
Very frequently asked in HCL Tech ( Based of 4 inputs ) | ||||
| ||||
Ans. Using String method - new StringBuffer(str).reverse().toString(); Iterative - public static String getReverseString(String str){ StringBuffer strBuffer = new StringBuffer(str.length); for(int counter=str.length -1 ; counter>=0;counter--){ strBuffer.append(str.charAt(counter)); } return strBuffer; } Recursive - public static String getReverseString(String str){ if(str.length <= 1){ return str; } return (getReverseString(str.subString(1)) + str.charAt(0); } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   reverse   stringbuffer   string class   code Asked in 6 Companies   frequent | ||||
| ||||
Ans. It's a programming technique wherein the method can call itself. The method call usually involves a different set of parameters as otherwise it would lead to an infinite loop. There is usually a termination check and statement to finally return the control out of all function calls. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   Asked in 1 Companies Basic | ||||
Frequently asked in Genpact. | ||||
| ||||
Ans. Its is the process of creating exact copy of an object being cloned. In Object class one native method called clone() is there which is meant for Shallow Cloning of Object. Shallow cloning means bitwise copy of an object.In case of primitive data type it will create an exact copy of primitive values as well as variables but if the object contains any reference of an object then it will not copy the referenced object rather it will create the copy of reference variable and assigned it to the old object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  cloning Asked in 3 Companies basic   frequent | ||||
| ||||
Ans. Lazy Loading is loading of entities on demand when subclass is called, while Eager loading is loading of all the sub entity at the start only. Eager loading is fast as all sub entities are already present, but its heavy(takes more memory) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   Asked in 1 Companies | ||||