Srinivas Cheruku
Srinivas Cheruku

Reputation: 1364

Abstract class having no abstract methods

It is a well established fact that abstract classes may or may not have abstract methods in it. But, once i was going through a website. Link: http://www.indiabix.com/technical/dotnet/object-oriented-programming/6

I could find out the following- Just have a look at the highlighted part. Screenshot

My question is, whether the highlighted part is false, as i am thinking. Or, it has some other meaning that is true and i have mistaken ?

Upvotes: 0

Views: 121

Answers (1)

Philip Pittle
Philip Pittle

Reputation: 12295

The article you are reading has several mistakes including the one you highlighted.

You must declare at least one abstract method in the abstract class.

As Jim Minschel pointed out, the C# Language Specifications explicitly state that an abstract class is not required to have abstract members. As your quoted source said method it is doubly wrong.

An abstract class is always public.

This is also completely wrong. An abstract class can be private, protected, protected internal, internal, or public.

For example, this code is perfectly fine:

 public class A
 {
      //Private and Abstract!
      private abstract class PrivateAbstract{}

      private class B : PrivateAbstract{}
 }

So given that the article has gotten wrong 2 out of 5 statements, I would recommend you find a different source for information on C#. Perhaps Rob Miles's free The C# Programming Yellow Book

Upvotes: 1

Related Questions