Skip to content

Commit 514a23a

Browse files
tostring method
1 parent e0ef465 commit 514a23a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Tostring method in java

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
//programme for how to use the toString method in java class
3+
//in this we use directly use public string tostring method or we can use object string and integer
4+
class hostel
5+
{
6+
String name;
7+
int no;
8+
9+
hostel(String a,int b)
10+
{
11+
this.name=a;
12+
this.no=b;
13+
}
14+
15+
public String toString()
16+
{
17+
return "your name is this "+name+" your roll number is this "+no;
18+
}
19+
20+
21+
}
22+
23+
public class Tostri {
24+
25+
public static void main(String[] args)
26+
{
27+
28+
hostel obj1= new hostel("vaghela Ajitkumar",45);
29+
30+
System.out.println(obj1);
31+
32+
//when we don't specify the string method its gives output like
33+
// its output like com.company.hostel@65ab7765
34+
35+
// after the specify the method its gives correct output
36+
System.out.println(obj1);
37+
//or
38+
// System.out.println(obj1.toString());
39+
40+
//wrapper class through
41+
String s1= new String("suffer is good but there is one confaction from my side");
42+
43+
System.out.println(s1);
44+
45+
Integer k1 =new Integer(13);
46+
//
47+
System.out.println(k1);
48+
}
49+
}

0 commit comments

Comments
 (0)