# How can we use this and super keywords in method reference in Java?

Java 8Object Oriented ProgrammingProgramming

The method reference is similar to a lambda expression that refers to a method without executing it and "::" operator can be used to separate a method name from the name of an object or class in a method reference.

The methods can be referenced with the help of this and super keywords in Java. The super keyword can be used as a qualifier to invoke the overridden method in a class or an interface.

## syntax

this::instanceMethod
TypeName.super::instanceMethod

## Example

import java.util.function.Function;

interface Defaults {
default int doMath(int a) {
return 2 * a;
}
}
public class Calculator implements Defaults {
@Override
public int doMath(int a) {
return a * a;
}
public void test(int value) {
Function<Integer, Integer> operator1 = this::doMath;
System.out.println("this::doMath() = " + operator1.apply(value));

Function<Integer, Integer> operator2 = Defaults.super::doMath;
System.out.println("Defaults.super::doMath() = " + operator2.apply(value));
}
public static void main(String[] args) {
Calculator calc = new Calculator();
calc.test(10);
}
}

## Output

this::doMath() =  100
Defaults.super::doMath() = 20
{"ft_lang_label":"__label__en","ft_lang_prob":0.648717,"math_prob":0.54773456,"size":2393,"snap":"2022-27-2022-33","text_gpt3_token_len":571,"char_repetition_ratio":0.14817916,"word_repetition_ratio":0.078085646,"special_character_ratio":0.2561638,"punctuation_ratio":0.14084508,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95298207,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-13T02:29:26Z\",\"WARC-Record-ID\":\"<urn:uuid:c9725a48-91ab-493e-bc12-32f60333387c>\",\"Content-Length\":\"31237\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6e61dcf8-d000-4ca8-b89f-8141bb21521a>\",\"WARC-Concurrent-To\":\"<urn:uuid:535f16cb-251c-4c12-9ec8-7f4171b40fff>\",\"WARC-IP-Address\":\"192.229.210.176\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/how-can-we-use-this-and-super-keywords-in-method-reference-in-java\",\"WARC-Payload-Digest\":\"sha1:HW5F3LDCDNRRZ673WOEJYOGH2G3ZP34R\",\"WARC-Block-Digest\":\"sha1:CHZJLIWCULJE72H77MJJNLZMMCEQXCLX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571869.23_warc_CC-MAIN-20220813021048-20220813051048-00391.warc.gz\"}"}