+ 4
Confused about a quiz
In one of the quizes for Java it is asked: Which of the following is used to reference a method? I answered ".", the other options were ";" and "::" and ",". But the correct answer was the option "::". I am confused. I think my answer is correct and I haven't seen this "::" notation in Java. but the answer sheet says it is the correct answer. please help me understand it!
7 Answers
+ 4
I've already reported it. Thanks for confirming my thought.
+ 3
:: is correct for use with a method reference. This is not the same as using a method from an instance of the class.
https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html
https://www.javatpoint.com/java-8-method-reference
https://www.codementor.io/eh3rrera/using-java-8-method-reference-du10866vx
+ 2
@ChaoticDawg I get error message trying to call static method of a class using :: (in Code Playground), can you please clarify what am I doing wrong?
https://code.sololearn.com/c68r0z4E2jC7/?ref=app
+ 2
@Ipang read through the links in my previous post and you'll see how to use method references properly. You're currently attempting to use them as a method call not a reference. For method calls you need to use dot notation. Look into lambdas and interfaces etc as well. Method references are used to pass the method as an argument into the calling method so that it may be used within the calling method. Think of the Arrays.sort() method which will take an array as its first parameter and an optional method as its second parameter that is used within the sort method to determine how items should be sorted.
+ 2
@Ipang this link should answer you cpp array length question and why it doesn't work with pointers or when the array is passed to a function.
https://stackoverflow.com/questions/4108313/how-do-i-find-the-length-of-an-array
+ 2
@ChaoticDawg mate, I have read the link, but having read it, I get more confusion than answer, debates were all I see in it, none pointed me to a certain direction, hard to get conclusion. Well maybe later I'll look again into it, hopefully with better reception. I really appreciate your help here mate, have a good day now :)
Thanks again,
+ 1
@ChaoticDawg mate, thanks for replying, I'll go back and read through the links again, I guess I misunderstood your point on previous answer, I was just verifying my thoughts, which seemed to have been wrong :).
I hate to bother you, but was wondering if you would help me on a C++ code, I tried creating function for finding smallest number in array, but I failed to predict the number of elements in the array, code included here:
Thanks in advance,
https://code.sololearn.com/cL3A3MZ1Sk4u/?ref=app