this keyword in java

class Other{
    public double num;
    public Other(int num){
        this.num = num;
        System.out.println(num);
      	//print 5 to the console
    }
}

class scratch{
    public static void main(String[] args) {
        Other method = new Other(5);
        System.out.println(method.num);
      	//prints 5.0 to the console
    }
}

4.13
8
Phoenix Logan 186120 points

                                    // this keyword in java example
import java.util.*;
class Demo
{
   // instance variable
   int m;
   int n;
   public void setValue(int m, int n)
   {
      m = m;
      n = n;
   }
   public void showValue()
   {
      System.out.println("Value m = " + m);
      System.out.println("Value n = " + n);
   }
}
public class ThisKeywordDemo
{
   public static void main(String[] args)
   {
      Demo obj = new Demo();
      obj.setValue(5, 6);
      obj.showValue();
   }
}

4.13 (8 Votes)
0
3.67
6
Awgiedawgie 440220 points

                                    // java program using ‘this’ keyword
class Demo
{
   int m;
   int n;
   public void setValue(int m, int n)
   {
      // java this keyword
      this.m = m;
      this.n = n;
   }
   public void showValue()
   {
      System.out.println("Value m = " + m);
      System.out.println("Value n = " + n);
   }
}
public class ThisExample
{
   public static void main(String[] args)
   {
      Demo obj = new Demo();
      obj.setValue(5,6);
      obj.showValue();
   }
}

3.67 (6 Votes)
0
0
2
Phoenix Logan 186120 points

                                    this() : used for calling the constructor . 
  we can only use it in the constructor
this. : used for calling the instance variables 
we can use in any object instances

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
use of this keyword in java detail What is ? this in java java when to use this keyword what this keyword in java this in javas This in java example what is the use of the this keyword in java this keyword use in java why we use }); keyword in java this java keyword java do you have to use this keyword What is “this” keyword in java? this:: java how to use this keyword in java program java keyword this uses of this keyword in java keyword this in java used to When is this keyword used in java this keyword hava keyword in java keyword this java what's this in java keyword this in java is used for java what is this keyword do this(java) java this in method what happens when we use new keyword in java this keyword in java with example this. java define this in java java this "this" keyword in java this() java java this keyword example what is keyword in java purpose of this keyword in java why we use that keyword in java that keyword in java this keyword definition in java why we use this keyword in java how this keyword works in java What is the use of 'this' keyword in java? this () in java this ()in java this keyword in java used for java why use this keyword why do we use this keyword in java java this. keyword Discuss the use of the keyword ‘this’ in Java Discuss the use of the keyword ‘this’ in Java. how to use this keyword in java with example what is "this" in java when to use this keyword in java keyword this in java what is the this keyword in java this keyword in java meaning what is new keyword in java in java what is this keyword why do we need this keyword in java the keyword this in java What is this keyword in java? what is this() in java this keyword in javas what is the use of this keyword in java this that java what is use of this keyword in java what is the use this keyword in java what does new keyword do in java this java how to use this in java this function in java this()in java what is the use of new keyword in java this.in java this java~ this:: in java what is this keyword in java can you use "and" keyword in java can you use and keyword in java this keyword in java is used to java thiskeyword what does the this keyword do in java this meaning java .this in java what is .this in java this keyword in java use what is a keyword in java when to use this keyword java\ this keyword example in java java this() keyword what the 'this' keyword is in Java this keword in java the this keyword in java this. in java keyword in java this in java explained when to use this. in java 5 applications of this keyword this keyword in javascript new keyword in java java new keyword Which of the following signifies incorrect usage of this keyword? EXPLAIN jAVA THIS method keyword in java Write a use for this keyword and provide an appropriate example demonstrating this use this keyword vs this mehto in java this->data in java if we create a this in method will it refer to class or function keyword argument java java and keyword explain this keyword in java this keyword what is this in java Keyword ………. is always a reference to the object keyword in oops wpf the shared field should refer to an instance this keyword in java MCQ what is implements keyword in java use this in java class param refers to currently executing objects java java this.method what does this. mean in java The “this” keyword refers to the object from where it is called. what are the applications of this pointer in java object.this java java why use this keyword? this keyword function in java in keyword in java What does ‘this’ keyword mean this.variable java this is used to refer current object this fuction java we can use this keyword to perform What is not the use of “this” keyword in Java? call this in java this is Java using this in java class java class illustrating this keyword diff way to use this keyword when to use this in java using java this. how to use this keyword in java what does this do in java using this in java this.a=a in java this statement in java why to use this in java how to use this as variable in java this keyword in java classes how to get object of object this.this in java this() in java best example for explaining this keyword java this operator how to use escape sequence in java methods in set in java what is get function used for in javascript which method is used to write on webpage in visual studio how to refer the database in javaScritp the use of this in java When would the this keyword be used in java this.name java why use this in java this. in java means this java meaning what exactly is this keyword in java what does this refer to in java this keyword in java java this.variable this keyword java use of this keyword in java java this what is this in java java this meaning java this keyword how to use the this keyword in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source