Yahoo India Web Search

Search results

  1. The this keyword refers to the current object in a method or constructor. The most common use of the this keyword is to eliminate the confusion between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter).

    • this: to refer current class instance variable. The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity.
    • this: to invoke current class method. You may invoke the method of the current class by using the this keyword. If you don't use the this keyword, compiler automatically adds this keyword while invoking the method.
    • this() : to invoke current class constructor. The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor.
    • this: to pass as an argument in the method. The this keyword can also be passed as an argument in the method. It is mainly used in the event handling.
    • 19 min
    • Using ‘this’ keyword to refer current class instance variables. class Test { int a; int b; Test(int a, int b) this.a = a; this.b = b; } void display() System.out.println("a = " + a + " b = " + b);
    • Using this() to invoke current class constructor. class Test { int a; int b; Test() this(10, 20); System.out.println("Inside default constructor \n");
    • Using ‘this’ keyword to return the current class instance. class Test { int a; int b; Test() a = 10; b = 20; } Test get() return this; void display() System.out.println("a = " + a + " b = " + b);
    • Using ‘this’ keyword as method parameter. class Test { int a; int b; Test() a = 10; b = 20; } void display(Test obj) System.out.println("a = " +obj.a + " b = " + obj.b);
  2. www.w3schools.com › java › java_ref_keywordsJava Keywords - W3Schools

    Java has a set of keywords that are reserved words that cannot be used as variables, methods, classes, or any other identifiers: Note: true, false, and null are not keywords, but they are literals and reserved words that cannot be used as identifiers. Previous Next .

    Keyword
    Description
    A non-access modifier. Used for classes ...
    For debugging
    A data type that can only store true or ...
    Breaks out of a loop or a switch block
  3. In Java, this keyword is used to refer to the current object inside a method or a constructor. For example, class Main { int instVar; Main(int instVar){ this.instVar = instVar; System.out.println("this reference = " + this); } public static void main(String[] args) { Main obj = new Main(8);

  4. www.javaguides.net › 2018 › 12this Keyword in Java

    In this article, we will learn everything about this keyword. In Java, this is a reference variable that refers to the current object. Check out All 50 Java Keywords with Examples. Let's discuss each of these usages of this keyword with an example.

  5. People also ask

  6. this keyword is a very important keyword to identify an object. Following are the usage of this keyword. this can be used to get the current object. this can be used to invoke current object's method. this() can be used to invoke current class constructor. this can be passed as a parameter to a method call. this can be passed as a parameter to ...

  1. People also search for