+ 1

Oops concept

What I have to do to redefine the toString method in my code to concatenate all text fields. https://code.sololearn.com/c7Yg20I3i2oS/?ref=app

29th May 2020, 10:31 AM
vinay kumar singh
vinay kumar singh - avatar
17 ответов
+ 1
Do you mind showing me what is your text variable going to hold? What do you expect as an output and why do you need to make use of a toString()? It is generally used to describe object properties.
29th May 2020, 1:05 PM
Avinesh
Avinesh - avatar
+ 1
You can apply his example for every object.
29th May 2020, 1:13 PM
Sandra Meyer
Sandra Meyer - avatar
0
Implement it. Use @Override annotation. If you have access to an IDE: They can auto-generate such methods.
29th May 2020, 11:59 AM
Sandra Meyer
Sandra Meyer - avatar
0
I don't see the use of Document class here. You can simply override the toString() like this. public String toSting(){ return "Sender: "+sender+"\nRecipient: "+recipient+"\nTitle: "+title; } And write something like this in main. public static void main(String[] args) { Email ob = new Email(); ob.setSender("Abc"); ob.setRecipient("Xyz"); ob.setTitle("Hello"); System.out.println(ob.toSting()); }
29th May 2020, 12:05 PM
Avinesh
Avinesh - avatar
0
Avinesh actually I have return text in toString() method of class Document and there is one more text variable in Email class. At the end I have to concatenate both the text field.
29th May 2020, 12:44 PM
vinay kumar singh
vinay kumar singh - avatar
0
Avinesh the body of the email message should be stored in the inherited text
29th May 2020, 12:45 PM
vinay kumar singh
vinay kumar singh - avatar
0
Sandra Meyer I dnt have access to an IDE. Will you please suggest something else which can work for me
29th May 2020, 12:46 PM
vinay kumar singh
vinay kumar singh - avatar
0
You'll have to write it manually then. Avinesh did post a sample for you.
29th May 2020, 12:53 PM
Sandra Meyer
Sandra Meyer - avatar
0
Sandra Meyer I have explained to Avinesh what exactly I am looking for...if u have any idea then let me know
29th May 2020, 12:55 PM
vinay kumar singh
vinay kumar singh - avatar
0
Avinesh define a class named Document that contains a member variable of type String named text that stores any textual content for the Document. Create a method named toString that returns a text field and also include a method to set this value. Next, define a class Email which is derived from Document and includes member variables as sender, recipient,title of an email message. Implement accessor and mutator. The body of the email message should be stored in the inherited variable text. Redefine the toString method to concatenate all text fields.
29th May 2020, 1:23 PM
vinay kumar singh
vinay kumar singh - avatar
0
Have a look Avinesh
29th May 2020, 1:23 PM
vinay kumar singh
vinay kumar singh - avatar
29th May 2020, 1:40 PM
Avinesh
Avinesh - avatar
0
Avinesh thanks alotttt
29th May 2020, 1:48 PM
vinay kumar singh
vinay kumar singh - avatar
0
vinay kumar singh you're welcome. Nice to know that I could help.
29th May 2020, 1:57 PM
Avinesh
Avinesh - avatar
0
sujit borade I m new to java..and I believe I am practicing thats y doubts raised
30th May 2020, 11:25 AM
vinay kumar singh
vinay kumar singh - avatar
0
sujit borade Am I not doing?
30th May 2020, 11:27 AM
vinay kumar singh
vinay kumar singh - avatar
0
sujit borade yes thn be aside..and stop poking
30th May 2020, 11:29 AM
vinay kumar singh
vinay kumar singh - avatar