Java - Interview Questions and Answers for 'Classes' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Classes' - 58 question(s) found - Order By Newest

 Q1. Why do we need Inner classes ? Cant we just work with outer classes wherever we implement Inner classes ?Core Java
Admin
info@buggybread.com
Ans. Yes, we can substitute outer classes wherever we need to have inner classes but Inner classes have advantage in certain cases and hence preferred -

Ease - Why to implement a class outside if its objects are only intended to be part of an outer object. Its easy to define the class within another class if the use is only local.

Protection - Making a call an outer exposes a threat of it being used by any of the class. Why should it be made an outer class if its object should only occur as part of other objects.

For example - You may like to have an class address whose object should have a reference to city and by design thats the only use of city you have in your application. Making Address and City as outer class exposes City to any of the Class. Making it an inner class of Address will make sure that its accessed using object of Address.

  Sample Code for inner class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   inner classes   classes   objects   technical lead      intermediate

Try 1 Question(s) Test


 Q2. What are different types of classes ?Core Java

Ans. There are different verticals in which Java Classes can be classified.

1. Access - Public , Private , default or Protected.

2. Packaging - System, library or User Defined

3. Structure - Outer or Inner

4. Object Derivation - Abstract Class or Concrete Class.

5. Object Creation - Normal, Singleton , Doubleton , Immutable or Enum.

6. Functionality - String , Util , Stream etc.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     classes   different types of classes     iFactor

Try 1 Question(s) Test


 Q3. What are the Disadvantages of using Collection Classes over Arrays ?Core Java
Admin
info@buggybread.com
Ans. Collections can only hold objects, It can't hold primitive data types.

Collections have performance overheads as they deal with objects and offer dynamic memory expansion. This dynamic expansion could be a bigger overhead if the collection class needs consecutive memory location like Vectors.

Collections doesn't allow modification while traversal as it may lead to concurrentModificationException.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   collections classes   disadvantages of collections over arrays   collections vs arrays


Very Frequently asked. Have been asked in HCL Technologies very frequently ( based on 2 feedback ). Among first few questions in many interviews.
  Q4. Differences between abstract class and interface ?Core Java
Admin
info@buggybread.com
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the derived classes ) whereas Interfaces can only have abstract methods ( method declarations ).

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   classes   abstract class   interfaces     GlobalLogic  HCL Technologies  Tata Consultancy (TCS)  Infosys  Wipro  Mindtree  CapitalOne  Accenture  IBM India  Infoview Technologies  Salesforce  AT&T  United Health Group (UHG)  Verilogue  Amazon  Expeditors  Syntel  SalesForce  Cornerstone OnDemand  Expedia  OLA  NSF International  Copper Mobile  Think Future Technologies  MorphoTrust  Global Healthcare  Prodigious  Internet Brands  SciQuest  arvato Systems  iCIMS  Ideas2IT  virtusa polaris  Vitech Systems  Cognizant (CTS)      basic        frequent


 Q5. Which of the following can be marked static ?

a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes
Core Java
Anonymous
Ans. Methods , Variables , Initialization Blocks and nested Classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q6. In which cases , moving methods to utility class could be useful ?Core Java

Ans. It could be worthy to move a method to util class if the method needs to be shared, doesn't require polymorphic behavior and need not be overridden in special cases.

Don't belong to one group through is-a relationship ( You can share through parent class method )

Don't implement a specific interface ( java 8 default methods )

Doesn't involve complex computing as you will be loosing the benefit of object state with just static method.

Doesn't require polymorphic behavior as static methods don't participate in runtime polymorphism.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     utility classes   util classes   static methods   application design        rare


 Q7. What is the difference between the following two code lines ?

1. new OuterClass().new InnerClass();

2. new OuterClass.InnerClass();
Core Java2016-06-30 14:45:37

Ans. In first case we are trying to initialize Inner class object using the instance of Outer Class whereas in second case we are trying to initialize the Inner class object directly using the Outer class name.

In second case , Inner class is "static inner class" as we cannot access "non static inner class" using Classname alone.

In first case, the inner class could be either "static inner class" or "non static inner class".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner classes  inner class   static inner class   new operator


  Q8. What are the different types of inner classes ?Core Java
Anonymous
Ans. Simple Inner Class,
Local Inner Class,
Anonymous Inner Class,
Static Nested Inner Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   inner classes   classes     Infosys  Tata Consultancy (TCS)  HCL Technologies  IBM  IBM India  Gateway Media      basic        frequent

Try 1 Question(s) Test


 Q9. What are the Wrapper classes available for primitive types ?Core Java
Anonymous
Ans. boolean - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   data types   wrapper classes   adapter design pattern        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What are wrapper classes ?Core Java
Anonymous
Ans. They are wrappers to primitive data types. They allow us to access primitives as objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   data types   wrapper classes     CSL  Xoriant  Webilent      basic        frequent


 Q11. Difference between Abstract and Concrete Class ?Core Java
Anonymous
Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   basic interview question     Goldman Sachs      basic        frequent


 Q12. Difference between boolean and Boolean ?Core Java
Anonymous
Ans. boolean is a primitive type whereas Boolean is a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   wrapper classes      basic        rare


 Q13. Explain Autoboxing ?Core Java
Anonymous
Ans. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   autoboxing   wrapper classes     Cognizant (CTS)      basic        frequent


 Q14. What are Wrapper Classes ? What are Primitive Wrapper Classes ?
Core Java
Anonymous
Ans. A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. A Wrapper Class that wraps or encapsulates the primitive data type is called Primitive Wrapper Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   primitive wrapper classes


 Q15. What Design pattern Wrapper Classes implement ?Design
Anonymous
Ans. Adapter.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   adapter design pattern   design pattern


 Q16. Difference between nested and inner classes ?
Anonymous
Ans. Inner classes are non static nested classes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   nested classes   inner classes   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q17. What is a nested interface ?
Anonymous
Ans. Any interface declared inside a class or an interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   nested classes


 Q18. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Anonymous
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   interfaces   advanced     ADP  AI corporation


 Q19. Will this code give error if i try to add two heterogeneous elements in the arraylist. ? and Why ?

List list1 = new ArrayList<>();
list1.add(5);
list1.add("5");
Admin
info@buggybread.com
Ans. If we don't declare the list to be of specific type, it treats it as list of objects.

int 1 is auto boxed to Integer and "1" is String and hence both are objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   arraylist   list   autoboxing   wrapper classes      expert        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. What are the restrictions for the entity classes ?Hibernate
Admin
info@buggybread.com
Ans. 1. Entity classes should have default constructor.

2. Entity classes should be declared non final.

3. All elements to be persisted should be declared private and should have public getters and setters in the Java Bean style.

4. All classes should have an ID that maps to Primary Key for the table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   entity classes hibernate


 Q21. Which of the following cannot be marked static ?

a. Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
b. Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
c. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
d. Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables
Anonymous
Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q22. Explain use of nested or inner classes ?
Anonymous
Ans. Sometime we just need classes or class objects just to be used as part of a particular class or objects. Making them non nested won't make any difference as far as functionality is concerner but making them Nested provide a level of convenience and protection fro, being used anywhere else. Moreover it helps reducing the Code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   inner classes   nested class   inner class     IBM

Try 1 Question(s) Test


 Q23. What is the benefit of inner / nested classes ?Core Java
Admin
info@buggybread.com
Ans. You can put related classes together as a single logical group.

Nested classes can access all class members of the enclosing class, which might be useful in certain cases.

Nested classes are sometimes useful for specific purposes. For example, anonymous inner classes are useful for writing simpler event-handling code with AWT/Swing.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   nested classes   inner classes   oops   classes

Try 1 Question(s) Test


 Q24. Explain Static nested Classes ?
Admin
info@buggybread.com
Ans. The accessibility (public, protected, etc.) of the static nested class is defined by the outer class.

A static nested class is not an inner class, it's a top-level nested class.

The name of the static nested class is expressed with OuterClassName.NestedClassName syntax.

When you define an inner nested class (or interface) inside an interface, the nested class is declared implicitly public and static.

Static nested classes can be declared abstract or final.

Static nested classes can extend another class or it can be used as a base class.

Static nested classes can have static members.

Static nested classes can access the members of the outer class (only static members, obviously).

The outer class can also access the members (even private members) of the nested class through an object of nested class. If you don’t declare an instance of the nested class, the outer class cannot access nested class elements directly.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   nested classes   static nested classes


 Q25. Explain Inner Classes ?Core Java
Admin
info@buggybread.com
Ans. The accessibility (public, protected, etc.) of the inner class is defined by the outer class.

Just like top-level classes, an inner class can extend a class or can implement interfaces.

Similarly, an inner class can be extended by other classes, and an inner interface can be implemented or extended by other classes or interfaces.

An inner class can be declared final or abstract.Inner classes can have inner classes, but you will have a hard time reading or understanding such complex nesting of classes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   classes   inner classes     Computer Sciences Corporation (CSC) India      Basic        frequent

Try 2 Question(s) Test


 Q26. Explain Method Local Inner Classes ?Core Java
Admin
info@buggybread.com
Ans. You can create a non-static local class inside a body of code. Interfaces cannot have local classes, and you cannot create local interfaces.

Local classes are accessible only from the body of the code in which the class is defined. The local classes are completely inaccessible outside the body of the code in which the class is defined.

You can extend a class or implement interfaces while defining a local class.

A local class can access all the variables available in the body of the code in which it is defined. You can pass only final variables to a local inner class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   inner classes   local classes   classes   method local inner classes     Cognizant (CTS)


 Q27. Explain about anonymous inner classes ?
Admin
info@buggybread.com
Ans. Anonymous classes are defined in the new expression itself, so you cannot create multiple objects of an anonymous class.

You cannot explicitly extend a class or explicitly implement interfaces when defining an anonymous class.

An anonymous inner class is always created as part of a statement; don't forget to close the statement after the class definition with a curly brace. This is a rare case in Java, a curly brace followed by a semicolon.

Anonymous inner classes have no name, and their type must be either a subclass of the named type or an implementer of the named interface

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   inner classes   anonymous inner classes   classes


 Q28. Advantage of Collection classes over Arrays ?
Admin
info@buggybread.com
Ans. Collections are re-sizable in nature. We can increase or decrease the size as per recruitment.
Collections can hold both homogeneous and heterogeneous data's.
Every collection follows some standard data structures.
Collection provides many useful built in methods for traversing,sorting and search.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   collections   collections classes   advantages of collections over arrays   collections vs arrays   basic interview question      basic        frequent


 Q29. Can we compare Integers by using equals() in Java ?Core Java
Admin
info@buggybread.com
Ans. Yes for the Wrapper class Integer but not for the primitive int.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   equals



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. Can we declare Entity class as final ?Hibernate
Admin
info@buggybread.com
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   proxy objects   proxy classes   entity hibernate


 Q31. What will the following code do ?

String dateStr = "2011 11 19";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(dateStr);
System.out.println(date);

admin
info@buggybread.com
Ans. It will throw the ParseException as the date format doesn't abide with the format of the specified date.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     date   utility classes   dateformat   exception   parseexception


 Q32. Is this valid in Java ?

Long x = new Long ("42");
Core Java
Admin
info@buggybread.com
Ans. Yes. Long wrapper class has overloaded constructor which takes String as input and then translate it to the long value and stored it as long.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   long wrapper class   long


 Q33. Will this Code compile ?

abstract public class BuggyBread1{
abstract public void test(){};
}
Core Java
Admin
info@buggybread.com
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no


 Q34. Can we have multiple classes in single file ?
admin
info@buggybread.com
Ans. Yes, but there can be only 1 public class in a single file.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   classes


 Q35. Which of the following is not type of inner classes ?

a. Simple Inner Class
b. Static Nested Inner Class
c. Method Nested Static Inner Class
d. Anonymous Inner Class
Anonymous
Ans. Method Nested Static Inner Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   classes   inner classes

Try 1 Question(s) Test


Must know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals.
  Q36. What is Inheritance ?Core Java

Ans. Its a facility for code reuse and independent extension wherein a derived class inherits the properties of parent class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inheritance  oops concepts  java concepts  code reuse  code re-use   classes  derived classes     Maverick Software  Infosys  HCL Technologies  Tata Consultancy (TCS)  Cognizant (CTS)  Myntra  Capital One  Barclays  Accenture  Infoview Technologies  Wipro  Paragyte      basic        frequent


 Q37. What is a Java Bean ? How is it different from other Java classes ?

Ans. A Java bean is a class which abides by following conventions:

Core of the object is member elements and not operations ( methods )

Member Elements can be accessed by getters (and setters if those properties are not read-only).

serializable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java bean   javabean   pojo   classes      basic        frequent


 Q38. In the following code , how many methods needs to be implemented in Class B ?

public interface A{
   public void method1();
   public void method2();
   public void method3();
}

abstract class B implements A{
}
Core Java

Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     interfaces  abstract classes  code  coding

Try 2 Question(s) Test


 Q39. Have you heard of Ban Duplicate Classes Maven enforcer plugin ? What is its use ?Maven2016-09-12 10:23:45

Ans. Yes , we have been using this plugin with our projects and its purpose is to warn and stop the Build if there are duplicates of the same package and class are being carried either directly or through transitive dependencies. the duplicate could be coming through different types of dependencies or through different versions of the same dependency. Its purpose is to make sure that there is only one copy thats being used at compile time and runtime and hence shouldnt later result in runtime problems.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     maven   ban duplicate classes enforcer plugin



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. How to tackle duplicate classes in maven build ?Maven2016-09-12 10:26:42

Ans. The simplest way is to ignore them if Maven enforcer plugin is complaining about it but it may lead to runtime problems later.

We can do the dependency:tree to see from where these duplicate ones are coming and hence can exclude the duplicate one.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     maven   ban duplicate classes enforcer plugin


 Q41. Can we have an inner class within Interface ?Core Java2016-10-24 11:18:24

Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner classes  inner class in interface  nested classes


 Q42. What are Collection Classes ?Core Java2016-12-18 16:52:03

Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     collections  collection classes     Infoview Technologies      Basic        frequent


 Q43. When should we use Abstract classes ?Core Java2016-12-23 20:12:52

Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as inheritance ( extending abstract class ). So they should be used in place of interfaces in case there is some code ( methods ) or object body ( member elements ) that can be reused with inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract classes     Polaris


 Q44. how to access the methods of an inner class?Core Java2017-01-14 11:11:38

Ans. It depends on the type of inner class

To access non static inner class method

new OuterClass().new InnerClass().getMethod();

To access static method of static inner class

new OuterClass.InnerClass().getMethod();

  Sample Code for inner class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner classes  nested aclasses     SuccessFactors      Intermediate        frequent


 Q45. What are Util Classes ? What are its advantages ?Core Java2017-03-10 10:48:48

Ans. Classes having only static methods in java is called util classes. As they don't have specific object state, they are basically intend to have shared code and state through static elements and methods. They save resources by sharing code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     util classes

Try 1 Question(s) Test


 Q46. What is Boxing conversion ?Core Java2017-06-06 12:31:36

Ans. Boxing conversion converts expressions of primitive type to corresponding expressions of reference type.

For example

boolean to Boolean
long to Long
double to Double

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     data type  boxing  wrapper classes


 Q47. Can an interface be defined inside a class just like we can have inner classes inside a class ?Core Java2017-06-23 08:13:43

Ans. Yes , we can have an interface that is part of a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class   inner interface  nested classes


 Q48. Does Wrapper classes produces immutable objects ? Core Java2017-08-08 09:46:33

Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     wrapper classes  immutable


 Q49. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java2017-08-17 19:28:33

 This question was recently asked at 'Proofpoint'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract classes  interfaces  default method     Proofpoint      expert



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q50. Why can we have a static inner class but not a static Top level class in Java ?Core Java2017-08-23 20:14:59

 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     static class  inner classes      Expert        rare


 Q51. What are the benefits of using Wrapper classes over primitive types ?Core Java2017-08-24 21:35:53

Ans. With Collection classes , we cannot use primitive types. Moreover for any class using generic types, we cannot use primitive types.

They add more functionality by means of additional methods.

As their reference can be null , they offer consistent check for uninitialized state.

They facilitate caching and reuse by means of constant Pools.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     wrapper classes  benefits of wrapper classes over primitives


 Q52. Can we use primitive types with Collection classes ?Core Java2017-08-24 21:36:52

Ans. No, As collection classes involve use of Generics, they cannot accept primitive types.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     collection classes  collections


 Q53. Is immutability an advantage with Wrapper classes over primitive types ? Core Java2017-08-24 21:43:19

Ans. There is no concept of de referencing with primitive types and hence they are implicitly immutable. Having wrapper classes as mutable offers disadvantages compared to primitive types. Wrapper classes being immutable offer similar advantage as primitive types.It actually overshadows the disadvantage wrapper class could have if they are immutable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     immutable classes  wrapper classes


 Q54. Which immutable classes have you worked with ? Can you name some immutable Collections ? How to make an immutable collection ?Core Java2017-08-28 17:11:22

 This question was recently asked at 'Ancestry,HCL Technologies,Tata Consultancy (TCS)'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     immutability  immutable classes   immutable collections     Ancestry  HCL Technologies  Tata Consultancy (TCS)


 Q55. What are the benefits of immutability or Immutable classes ?Core Java2017-08-28 19:36:18

 This question was recently asked at 'Ancestry'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     immutable classes   benefits of immutable classes     Ancestry


 Q56. Which of following can be nested into another ?Core Java
a. class within another class
b. class within interface
c. interface within class
d. All of above

Ans.d. All of above

 Q57. An Ideal Util class doesn't have ...Core Java
a. private constructor
b. static methods
c. static variables
d. non static methods

Ans.d. non static methods

 Q58. Which of the following class cannot be extended or inherited ?

StringBuffer , StringBuilder
Core Java
a. StringBuffer
b. StringBuilder
c. Both cannot be extended
d. Both can be extended

Ans.c. Both cannot be extended



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: