3 static method oopii 1 oop1 recapped 4 non static

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gram.exe — Or, double click the executable at the Windows Explorer. 3 Static Method OOP(II) 1 - OOP(1) Recapped 4 Non-Static (Instance) Method // filename: Tool.cs public class Tool { public static void Use() { ... } } // filename: Tool.cs public class Tool { public void Do() { ... } } // filename: UseTool.cs public class UseTool { public static void Main() { Tool.Use(); } } // filename: UseTool.cs public class UseTool { public static void Main() { Tool x = new Tool(); x.Do(); } } — To compile: — To compile: csc /out:Main.exe Tool.cs UseTool.cs OOP(II) 1 - OOP(1) Recapped csc /out:Main.exe Tool.cs UseTool.cs 5 OOP(II) Leo Leung PDF created with pdfFactory trial version www.pdffactory.com 1 - OOP(1) Recapped 6 1 OOP(II) 1 - OOP(I) Recapped Object can carry Data Private Data Public Getter/Setter // filename: Tool.cs public class Tool { private int level = 1; public Tool() { } public Tool(int level) { this.level = level; } ... } // filename: Tool.cs public class Tool { private int level = 1; public int Level { get { return level; } set { if (value >= 1 && value <= 3) level = value; } } public Tool() { } public Tool(int level) { Level = level; } ... } // filename: UseTool.cs public class UseTool { public static void Main() { Tool t0 = new Tool(); // create a default level tool Tool t1 = new Tool(1); // create a level-1 tool Tool t2 = new Tool(2); // create a level-2 tool } } OOP(II) 1 - OOP(1) Recapped...
View Full Document

Ask a homework question - tutors are online