+ 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
17 Réponses
+ 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.
+ 1
You can apply his example for every object.
0
Implement it. Use @Override annotation. If you have access to an IDE: They can auto-generate such methods.
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());
}
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.
0
Avinesh the body of the email message should be stored in the inherited text
0
Sandra Meyer I dnt have access to an IDE. Will you please suggest something else which can work for me
0
You'll have to write it manually then. Avinesh did post a sample for you.
0
Sandra Meyer I have explained to Avinesh what exactly I am looking for...if u have any idea then let me know
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.
0
Have a look Avinesh
0
See if this works.
https://code.sololearn.com/cJR2MnpLjimA/?ref=app
0
Avinesh thanks alotttt
0
vinay kumar singh you're welcome.
Nice to know that I could help.
0
sujit borade I m new to java..and I believe I am practicing thats y doubts raised
0
sujit borade Am I not doing?
0
sujit borade yes thn be aside..and stop poking