জাভার this কীওয়ার্ড খুবই গুরুত্বপূর্ণ। জাভাতে এই কীওয়ার্ড প্রচুর পরিমানে ব্যবহৃত হয়। আজকে আমরা এর চারটি গুরুত্বপূর্ণ ব্যবহার সম্পর্কে জানব।
১. যেভাবে কোনো অবজেক্ট ক্লাসের সকল উপাদান যেমন ফাংশন এবং কন্সট্রাক্টরকে নির্দেশ করে টিক তেমনি "this" কীওয়ার্ড ঐ অবজেক্ট কে নির্দেশ করে।
public class A {
void dis()
{
System.out.println(this);
}
}
class B{
public static void main(String[] args) {
A res=new A();
System.out.println(res);
res.dis();
}
}
public class A {
int x; // ইনস্ট্যান্স ভ্যারিয়েবল
A (int x) // int x ->লোকাল ভ্যারিয়েবল এবং এটি একটি ডিফল্ট কন্সট্রাক্টর
{
this.x=x; // this.x -> ইনস্ট্যান্স ভ্যারিয়েবল
}
void dis()
{
System.out.println(x);
}
}
class B{
public static void main(String[] args) {
A res=new A(5); // অবজেক্ট তৈরি হতেই ডিফল্ট কন্সট্রাক্টরকে কল করবে।
res.dis();
}
}
public class A {
A ()
{
System.out.print("I Love you Bangladesh");
}
A (int x)
{
this();
System.out.print(" "+x+" ");
}
}
class B{
public static void main(String[] args) {
A res=new A(3000);
}
}
public class A {
A ()
{
this(3000);
}
A (int x)
{
System.out.print(x);
}
}
class B{
public static void main(String[] args) {
A res=new A();
}
}
WorldTimeTech provides Top News,Education, Health Tips, Lifestyle, Science and Technology, Computer Help Tips and Unknown facts and also more and more. We Always Try to Give You Helpful Content to you. Thank You...
Copyright © 2023 WorldTimeTech.com All Rights Reserved.