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.
Ans. They are usually instance methods. They are usually applied to DAOs / DTOs / POJO that are used to transport objects and used to access object elements. As they are tied to objects and are not common to all objects of a class, hence they are created as non static.
Help us improve. Please let us know the company, where you were asked this question :
Q335. How would you choose your favorite company name for e.g. three companies are given in radio buttons Infosys, TCS and Aricent. Do You need to loop trough all radio buttons and select your favorite company or can just get the selected value.
Ans. Map<DataType1,DataType2> where DataType1 is the data type of element1 ( returned by getelement1 method ) and DataType2 is the data type of element2 ( returned by getElement2 method )
Help us improve. Please let us know the company, where you were asked this question :
Ans. We are averaging elements of a collection by element1 grouped by element1
* list is the reference of collection
* element1 is the member element returned by getElement1 method of ClassA
* element2 is the member element returned by getElement2 method of ClassA
Help us improve. Please let us know the company, where you were asked this question :
Ans. There are different types of relationship between classes
Inheritance - Also called is-a relationship, Child class object carries the body of the Parent class when initiated. Moreover there are certain privileges attach to method overriding to the classes related this way. This relationship exist for code reuse, method overriding and interfacing ( through abstract class ).
Composition - Also called has-a relationship. Class objects carries a reference to other class objects when instantiated. This relationship exist for work flow / work delegation.
Inner / Nested class - It’s a relationship that encapsulates the inner class or it’s object within the outer class. This relationship exist for encapsulation / security.
Help us improve. Please let us know the company, where you were asked this question :
Ans. No. The whole idea of default method is to provide a default definition in case the implementing class intend to provide definition for only some of the methods. Making any of the interface method private would restrict it from being implemented by the implementing class. So default method is an option to provide implementation and not restricting a new definition.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Java 8 allowed for method implementation using default methods in interfaces. As those default methods could contain complex logic and might need organizing the logic into multiple methods, they have allowed for private methods.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Java 9 would provide an error at compile time if there are different modules with the same package mapped to the same class loader and hence would provide a compile time check for this issue.
NoClassDefFoundError exists because of ambiguity at realtime because of multiple versions of same package / class exist. As Java 9 would provide a compile time check for it through clearly defined dependencies and exports and a check on duplicate packages being loaded by single class loader, it will fix the problem.
Help us improve. Please let us know the company, where you were asked this question :
Ans. As one purpose of automatic module is to provide backward compatibility with the module less dependencies, automatic modules exports all packages and include all other modules.
Help us improve. Please let us know the company, where you were asked this question :