Java Challenge. Explanation 2
#1 Does constructor return any value? (+) Yes ( ) No This is a little confusing. I thought constructors do not return a value - it is operator 'new' that does. It returns a reference to a newly created instance of the class. Is that instance considered to be a return value constructor returns? #2 Which of these can be used to differentiate two or more methods having the same name? (+) Number of parameters ( ) Parameters data type ( ) None of these What about parameters data type? Suppose we have 2 methods: - boolean isTrue (int a, int b); - boolean isTrue (double a, double b); #3 Java allows to create a method which has the name as the class. - If I create such a NON-STATIC method and specify 'void' return type for it, the method can be accessed from a static context (e.g. main function) - If I create such a NON-STATIC method and specify 'int' return type for it, then I try to call it from a main method, compilation shows an error How to explain such a behaviour? #4 https://code.sololearn.com/crY69h5Ll2L6/#java Question 1. When do we practically use it? Question 2. Suppose another class D implements interace A as well and overrides its methods. Let's create A d = new D(); How does compiler know, which method implementation should be executed (the one in B or the one in D class)? I thought it depends on a data type of the variable that stores a reference. But here the data type is the same for both cases. #5 https://code.sololearn.com/c06e4Z9zk18w/#java Why the method with a String argument gets executed? #6 https://code.sololearn.com/cglH9JWxldgF/#java Why the output is false? Should we use equals() method with strings only? Suppose we have 2 static Integer objects defined in the same class and initialized with the same value. https://code.sololearn.com/cUc53zVkkGWH/#java Calling this method on these objects returns true. What is the explanation for this?