{"id":1520,"date":"2022-03-05T06:33:03","date_gmt":"2022-03-05T06:33:03","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1520"},"modified":"2022-03-05T06:33:03","modified_gmt":"2022-03-05T06:33:03","slug":"can-we-assign-the-reference-to-this-variable","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/05\/can-we-assign-the-reference-to-this-variable\/","title":{"rendered":"Can we assign the reference to\u00a0this\u00a0variable?"},"content":{"rendered":"\n<p>No, this cannot be assigned to any value because it always points to the current class object and this is the final reference in Java. However, if we try to do so, the compiler error will be shown. Consider the following example.<a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/corejava-interview-questions#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Test  \n{  \n    public Test()  \n    {  \n        this = null;   \n        System.out.println(\"Test class constructor called\");  \n    }  \n    public static void main (String args&#91;])  \n    {  \n        Test t = new Test();  \n    }  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test.java:5: error: cannot assign a value to final variable this\n        this = null; \n        ^\n1 error<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>No, this cannot be assigned to any value because it always points to the current class object and this is the final reference in Java. However, if we try to do so, the compiler error will be shown. Consider the following example. Output<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[535],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1520"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1520"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1520\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}