Guide to the Language


Abstract Classes and Interfaces


Download 2 Mb.
Pdf ko'rish
bet48/78
Sana30.04.2023
Hajmi2 Mb.
#1414515
TuriGuide
1   ...   44   45   46   47   48   49   50   51   ...   78
Bog'liq
C sharp

 Abstract Classes and Interfaces
Abstract classes are similar to interfaces in many ways. Both can define 
member signatures that deriving classes must implement, yet neither one 
of them can be instantiated. The key differences are first that the abstract 
class can contain non-abstract members, while the interface cannot. And 
second, a class can implement any number of interfaces but only inherit 
from one class, abstract or not.
Chapter 18 abstraCt


112
// Defines default functionality and definitions
abstract class Shape
{
public int x = 100, y = 100;
public abstract int GetArea();
}
class Rectangle : Shape {} // class is a Shape
// Defines an interface or a specific functionality
interface IComparable
{
int Compare(object o);
}
class MyClass : IComparable {} // class can be compared
An abstract class, just like a non-abstract class, can extend one base 
class and implement any number of interfaces. An interface, however, 
cannot inherit from a class. It can inherit from another interface, which 
effectively combines the two interfaces into one.
Chapter 18 abstraCt


113
© Mikael Olsson 2020 
M. Olsson, C# 8 Quick Syntax Reference
https://doi.org/10.1007/978-1-4842-5577-3_19
CHAPTER 19
Namespaces
Namespaces provide a way to group related top-level members into 
a hierarchy. They are also used to avoid naming conflicts. A top-level 
member, such as a class, that is not included in a namespace is said to 
belong to the default namespace. It can be moved to another namespace 
by being enclosed in a namespace block. The naming convention for 
namespaces is the same as for classes, with each word initially capitalized.
namespace MyNamespace
{
class MyClass {}
}

Download 2 Mb.

Do'stlaringiz bilan baham:
1   ...   44   45   46   47   48   49   50   51   ...   78




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling