I am a newbie attempting to learn OOP with C#. I have 2 classes - base class = LibraryAsset and derived class = Book. The private fields for the 2 classes are below.
Library Asset: _title, _checkedOut
Book: _isbn, _author
I have written the necessary properties and methods.
The following code runs when the program starts
Book myBook = new Book();
myBook.Author = "John Doe";
myBook.CheckedOut = false;
myBook.ISBN = "554666";
myBook.Title = "Learning OOP";
myBook.CheckOut();
Console.WriteLine(myBook);
I have an ToString override method in the Book class and the LibraryAsset to return the associated fields. See below:
public override string ToString() // from Book Class
{
return String.Format( "Author: {0} \nISBN: {1}",
_author,_isbn);
}
public override string ToString() // from LibraryAsset class
{
return String.Format("Title: {0} \nChecked Out: {1}",
_title,_checkedOut);
}
My question is how do I write out all of the myBook properties to the screen. Console.WriteLine(myBook) only writes out the _author and _isbn. What do I need to do to write out the _title and _checkedOut?
Thanks for your help!
Library Asset: _title, _checkedOut
Book: _isbn, _author
I have written the necessary properties and methods.
The following code runs when the program starts
Book myBook = new Book();
myBook.Author = "John Doe";
myBook.CheckedOut = false;
myBook.ISBN = "554666";
myBook.Title = "Learning OOP";
myBook.CheckOut();
Console.WriteLine(myBook);
I have an ToString override method in the Book class and the LibraryAsset to return the associated fields. See below:
public override string ToString() // from Book Class
{
return String.Format( "Author: {0} \nISBN: {1}",
_author,_isbn);
}
public override string ToString() // from LibraryAsset class
{
return String.Format("Title: {0} \nChecked Out: {1}",
_title,_checkedOut);
}
My question is how do I write out all of the myBook properties to the screen. Console.WriteLine(myBook) only writes out the _author and _isbn. What do I need to do to write out the _title and _checkedOut?
Thanks for your help!