17, ఫిబ్రవరి 2015, మంగళవారం

SIMPLE EXAMPLE ABOUT JAVA.LANG.OBJECT



class Student
{
int sno;
String sname;
Student(int sno,String sname)
{
this.sno=sno;
this.sname=sname;}

/*public String toString()
{ return "STUDENT ID IS  "+sno+"\n"+"SNAME IS "+sname; }*/
}
public class TestObject
{
public static void main(String ramu[])
{
Student s=new Student(100,"ramu@dayina");
System.out.println(s);
}}


Output:- before overriding toString() method jvm executing object class toString() by default
D:\Threads>java TestObject
Student@1db9742   ->   classname@hashcode

After defining by the user toString()
D:\Threads>java TestObject
STUDENT ID IS  100
SNAME IS ramu@dayina

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి