//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
//With Out This Keyword
class A
{
int id;
A(int id)
{
id = id;
}
void test()
{
System.out.println(id);
}
public static void main(String args[])
{
A a1 = new A(1);
A a2 = new A(2);
a1.test();
a2.test();
}
}
6. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
//With This Keyword
class B
{
int id;
B(int id)
{
this.id = id;
}
void test()
{
System.out.println(id);
}
public static void main(String args[])
{
B b1 = new B(101);
B b2 = new B(201);
b1.test();
b2.test();
}
}
7. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class C
{
void test3()
{
System.out.println("test3");
test2(); //complier will add this automatically
}
void test1()
{
System.out.println("test1");
}
void test2()
{
System.out.println("test2");
this.test1(); //NO need to put this
}
public static void main(String args[])
{
C c1 = new C();
c1.test3();
}
}
8. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class D
{
void test2()
{
System.out.println("test2");
test1(this);
}
void test1(D d2)
{
System.out.println("test1");
}
public static void main(String args[])
{
D d1 = new D();
d1.test2();
}
}