Professional Documents
Culture Documents
Coopp
Coopp
C# - WHAT IS OOP?
When the individual objects are created, they inherit all the variables
and methods from the class.
Create an Object
An object is created from a class.
To create an object specify the class name, followed by the object
name, and use the keyword new
Object Methods
M e th ods n or m a lly be lo ng s to a c la ss , an d the y de fin e ho w a n obje ct of a c la s s
be h a ve s .
Ju s t lik e with fiel ds , you ca n a c c e s s m e th ods wit h th e do t sy nta x. Ho we ve r ,
n ote t ha t th e m e tho d m u s t be pu blic . A n d r e m e m be r t h at we us e th e n a m e of
th e m e t h od fo llowed by two pa ra n th e s e s () a nd a se m ic ol on ; to c a ll th e
m e th od
ACCESS MODIFIERS
Fields can be made read-only (if you only use the get method),
or write-only (if you only use the set method)
Another way to achieve abstraction in C#, is with interfaces.
An interface is a completely "abstract class", which can only contain
abstract methods and properties
To access the interface methods, the interface must be "implemented"
by another class. To implement an interface, use the : symbol . The
body of the interface method is provided by the "implement" class.
Note that you do not have to use the override keyword when
implementing an interface:
Like abstract classes, interfaces cannot be used to create objects.
Interface methods do not have a body - the body is provided
by the "implement" class