Write a program in java to demonstrate toString() method?

class Convert

{

                public static void display(String s)

                {

                                System.out.println(s);

                }

}

class ToString

{

                public static void main(String arg[])

                {

                                int a=5;

                                char b='V';

                                boolean c=false;

                                Convert.display(a);

                                Convert.display(b);

                                Convert.display(c);

                }

}

toString() method error.PNG

class Convert

{

                public static void display(String s)

                {

                                System.out.println(s);

                }

}

class ToString

{

                public static void main(String arg[])

                {

                                int a=5;

                                char b='V';

                                boolean c=false;

                                Convert.display(Integer.toString(a));

                                Convert.display(Character.toString(b));

                                Convert.display(Boolean.toString(c));

                }

}

toString() method.PNG

, , , , , ,

Leave a Reply