Reputation: 23
This is my class stock all my attributes in the stock class have to be protected other attributes and methods are public.
My problem is in the Book class which inherits from the Stock Class
abstract public class Stock
{
protected int libraryNum;
protected string title;
protected Member member;
protected DateTime returnDate;
private int id;
private string strtitle;
public Stock(int id, string strtitle)
{
libraryNum = id;
title = strtitle;
returnDate = DateTime.Now;
member = null;
}
public override string ToString()
{
return base.ToString();
}
}
public class Journal :Stock
{
private int vol;
public Journal(int vol, string strtitle, int id) : base(id, strtitle)
{
}
public override string ToString()
{
return base.ToString();
}
}
Down here I get a squiggle red line under the id in the Base(id, Strtitle) it says inaccessible due to its protection level. I am not sure how to make it accessible.
public class Book : Stock
{
private string authour;
public Book(string strtitle, string strauthor, int intid) : base(id, strtitle)
{
}
public override string ToString()
{
return base.ToString();
}
}
Upvotes: 0
Views: 129
Reputation: 839
Change the line:
abstract public class Stock
To:
public abstract class Stock
Also:
You are calling the base class constructor and attempting to pass in variable id but you are passing in intid. id is a field of the abstract class Stock, where as intid is the parameter. You are telling the implementing class to call it's base class with a field value that already belongs to the base class. The id is private so it isn't seen by the implementing class.
Upvotes: 0
Reputation: 49095
You probably meant to pass intid
instead of id
which is indeed private
to the (parent) Stock
class.
Try this:
public Book(string strtitle, string strauthor, int intid) : base(intid, strtitle)
Upvotes: 2