Object
Object
public final void wait()throws causes the current thread to wait, until
InterruptedException another thread notifies (invokes notify()
or notifyAll() method).
Student()
{
roll_no = last_roll;
last_roll++;
}
// Overriding hashCode()
@Override
public int hashCode()
{
return roll_no;
}
System.out.println (s.hashCode());
System.out.println (s.toString());
public class Test
{
public static void main(String[] args)
{
Object obj = new String(“HelloWorld");
Class c = obj.getClass();
System.out.println("Class of Object obj is : “ + c.getName());
}
}
try{
this keyword in java
• this is a reference variable that refers to the
current object.
• used to refer current class instance variable.
• used to invoke current class method
(implicitly)
• this() can be used to invoke current class
constructor.
class Student{
int rollno;
String name;
float fee;
Student(int rollno,String name,float fee)
{
this.rollno=rollno;
this.name=name;
this.fee=fee;
}
void display()
{
System.out.println(rollno+" "+name+" "+fee);
}
}
class TestThis{
public static void main(String args[]){
Student s1=new Student(111,"ankit",5000f);
Student s2=new Student(112,"sumit",6000f);
s1.display();
s2.display();
}}
class A{
void m()
{
System.out.println("hello m");
}
void n()
{
System.out.println("hello n");
//m();//same as this.m()
this.m();
}
}
class TestThis{
public static void main(String args[])
{
A a=new A();
a.n();
}
}
class A{
A()
{
System.out.println("hello a");
}
A(int x)
{
this();
System.out.println(x);
}
}
class TestThis{
public static void main(String args[])
{
A a=new A(10);
}
}