Lect 2.4 Key OO Features of Csharp

Lect 2.4 Key OO Features of Csharp - Lecture 2.4 Key OO...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 2.4 Key OO Features of C# MAIN TOPICS: Classes Objects Encapsulation Polymorphism Inheritance References: Deitel et al., C# How to Program , Prentice Hall, 2002
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key OO Features of C# 2 Topics Classes Objects Encapsulation Polymorphism Inheritance
Background image of page 2
Key OO Features of C# 3 Classes A class encapsulates (wrap together) data and methods – data members - member variables or instance variables – methods - manipulate data members User-defined aggregate data types C# does not distinguish between class interface (declaration) and implementation (definition) as C++ does
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key OO Features of C# 4 Classes (cont’d) C# class definition [Access modifier] class identifier [ : base class] {class body} private a nested class that can only be accessed inside the class in which it is defined public instances of this class are available to any class that wants to access it internal the class is only accessible from other classes in the same assembly
Background image of page 4
Key OO Features of C# 5 Classes (cont’d) C# class definition [Modifier] class identifier [ : base class] {class body} sealed the class cannot serve as a base class for another class abstract an instance of the class cannot be created
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key OO Features of C# 6 Classes (cont’d) Access to C# class members private member functions of the class protected member functions of the class and its derived class internal member functions of the class and classes of the current assembly protected internal member functions of the class and derived class, classes of the current assembly public all functions Member what functions can access the class member Java: private (No modifier) package* protected public
Background image of page 6
Key OO Features of C# 7 Assembly An assembly is the primary building block of a .NET Framework application It is a collection of functionality that is built, versioned, and deployed as a single implementation unit containing one or more files C# assemblies share a lot in common with Java JAR files. Assemblies are usually stored as EXEs or DLLs while JAR files are stored in the ZIP file format.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Key OO Features of C# 8 Assembly (cont’d) using System; namespace strTest { class AString { int length; string str; public AString( ) { str = “”; length = 0; } public AString( string initial ) { str = initial; length = str.Length; } public int getLength( ) { return length; } } class Class1 { static void Main ( string[ ] args ) { AString mystr = new AString( “Hello World” ); Console.WriteLine( mystr.getLength( ) ); } } } StrTest.cs
Background image of page 8
Key OO Features of C# 9 Assembly (cont’d) using System; namespace strTest { class AString { int length; string str; public AString( ) { str = “”; length = 0; } public AString( string initial ) { str = initial; length = str.Length; } public int getLength( ) { return length; } } } AString.cs using System; namespace strTest { class Class1 { static void Main ( string[ ] args ) { AString mystr = new AString( “Hello World” ); Console.WriteLine( mystr.getLength( ) ); } } } Class1.cs
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course SCE CSC301 taught by Professor Mr.leong during the Fall '10 term at Nanyang Technological University.

Page1 / 48

Lect 2.4 Key OO Features of Csharp - Lecture 2.4 Key OO...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online