toString() program in java










class A {



static int i=5;




/* public String toString() {


return "i="+i;

}

void myMethod(){

System.out.println("Aman");

}*/



public static void main(String[] args) {


A obj =

new A();


System.

out.println("obj.toString()----"+obj.toString());


System.

out.println( Integer.toString(i));


System.

out.println(obj.hashCode());



/* System.out.println("obj.hashCode()----"+obj.hashCode());


A obj1 = new A();

System.out.println("obj.toString()----"+obj.toString());

System.out.println("obj1-----"+obj1);

System.out.println("obj1.hashCode()-----"+obj1.hashCode());

System.out.println("equals method-----"+obj.equals(obj1));

A obj3=obj;

System.out.println(obj3.equals(obj));

System.out.println(obj.toString());*/


}



}

Comments

Popular posts from this blog