Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialXiaolong Yang
4,374 PointsBase class is less accessible than subclass
I tried to change "public class SequenceDetecter" to "abstract class SequenceDetecter", but it tells me that "base class Treehouse.CodeChallenges.SequenceDetector' is less accessible than class
Treehouse.CodeChallenges.ReapeatDetecter' ". It could pass only if I write "public abstract class SequenceDetecter", why? In the video, public was not included...
namespace Treehouse.CodeChallenges
{
abstract class SequenceDetector
{
public virtual string Description => "";
public int[] LastScannedSequence { get; protected set; }
public virtual bool Scan(int[] sequence)
{
LastScannedSequence = sequence;
return true;
}
}
}
namespace Treehouse.CodeChallenges
{
public class RepeatDetector : SequenceDetector
{
public override string Description => "Detects repetitions";
public override bool Scan(int[] sequence)
{
LastScannedSequence = sequence;
if(sequence.Length < 2)
{
return false;
}
for(int i = 1; i < sequence.Length; ++i)
{
if(sequence[i] == sequence[i-1])
{
return true;
}
}
return false;
}
}
}
1 Answer
Steven Parker
231,198 PointsThe access level of the class in the video was different.
In the video, class Invader was not public to begin with, so that aspect of it did not change.
But in this challenge, SequenceDetector was already public. And, as you discovered, it must remain that way because it is used as a base for RepeatDetector, which is also public.
Xiaolong Yang
4,374 PointsXiaolong Yang
4,374 PointsSorry for replying so late, thanks for your help ~~