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. It means that the type of variables are checked at compile time in Java.The main advantage here is that all kinds of checking can be done by the compiler and hence will reduce bugs.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Declaration is intimation to the compiler about the nature of Data a reference is going to hold.
For example - List myList;
Instantiation is reservation of memory.
For example
myList = new ArrayList();
Initialization or construction is setting the default values for member elements.
For example
myList = new ArrayList(mySet);
** Example 2nd is both for instantiation as well as initialization. The only difference is that 2nd will initialized the member elements to their default values whereas 3rd will initialized it with the elements from set.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  declaration   instantiation   initialization   construction   declaration vs instantiation   instantiation vs initialization   declaration vs initialization Asked in 1 Companiesbasic  frequent
Ans. No. Because java internally treats var args as arrays and hence both method declarations will generate the same byte code and hence would result in ambiguity while determining call binding.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc.
We cannot access methods defined in String class or in any class in hierarchy between String and Object.
For example - we cannot do obj.append("abc") as it will now give compile time error.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Though var args are used rarely but they are pretty useful if a method is expected to receive variable number of arguments. For example - it's pretty useful for the main method as the caller has the flexibility to provide arguments in infinite ways.It provides a convenience and flexibility to the caller.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Var args is the feature of Java that allows a method to have variable number of arguments. Var args are used when we are not sure about the number of arguments a method may need. Internally java treats them as array.
Ans. Yes, it will give compilation error and java will complain about duplicate method. Java treat var args internally as arrays and hence would result in same byte code for both method's syntax.
Help us improve. Please let us know the company, where you were asked this question :