Java 23 | this keyword

  Рет қаралды 26

Rishi Yadav

Rishi Yadav

Күн бұрын

this is a reference variable that refers to the current object
The main purpose of using ‘this’ keyword is to differentiate the local variable and data members of class whenever the data members of the class and the local variables have the same names without creating the ambiguity to JVM
Public class Rectangle{
int length, width;
Rectangle (int length, int width)
{
this.length = length;
this.width = width;
}
It can be used to call one constructor within the other constructor without creating the objects multiple tome for the same class.
This helps to avoid code duplication
class Student {
int age;
Student ( )
{
this(20);
}
Student ( int age )
{
this.age =age;
}
public static void main(String args[]) {
Student ss= new Student( );
Student s = new Student(23);
System.out.println(s.age);
System.out.println(ss.age);
}
}
Output: - 23
20

Пікірлер
Java Classes & Objects
11:36
Keep On Coding
Рет қаралды 335 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 17 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 44 МЛН
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 12 МЛН
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 532 М.
Java Concurrency and Multithreading - Introduction
14:32
Jakob Jenkov
Рет қаралды 252 М.
Java interface 🦅
7:51
Bro Code
Рет қаралды 194 М.
Google Data Center 360° Tour
8:29
Google Cloud Tech
Рет қаралды 5 МЛН
MUST KNOW junior role JAVA interview questions
42:15
Keep On Coding
Рет қаралды 120 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
OOPS CONCEPTS - JAVA PROGRAMMING
20:24
Sundeep Saradhi Kanthety
Рет қаралды 2 МЛН
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 444 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 17 МЛН