Cs using system public class usetool public 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: 7 Getter/Setter is used like a Field // filename: UseTool.cs using System; public class UseTool { public static void Main() { Tool x = new Tool(10); // Console.Write(x.Level); // x.Level = 2; // Console.Write(x.level); // Console.Write(x.Level); // x.Level++; // x.Level = 10; // } } OOP(II) 1 - OOP(1) Recapped try to create a level-10 tool print 1 (not 10) level set to 2 error print 2 level set up by 1 level not changed 9 8 Constructors OOP(II) 1 - OOP(1) Recapped 10 Default Constructor // filename: Tool.cs public class Tool { private int level = 1; public int Level { get { ... } set { ... } } public Tool() : this(1) { // Level = 1; } public Tool(int level) { Level = level; } ... } 1 - OOP(1) Recapped 1 - OOP(1) Recapped // filename: Tool.cs public class Tool { private int level; public int Level { get { ... } set { ... } } public Tool() { Level = 1; } public Tool(int level) : this() { Level = level; } ... } Constructors OOP(II) OOP(II) public class Tool { private int level = 1; public int Level { ... } public Tool() {} } public class UseTool { public static void Main() { Tool x = new Tool(); // ok } } 11 OOP(II) Leo Leung PDF created with pdfFactory trial version www.pdffactory.com 1 - OOP(1) Recapped 12 2 OOP(II) 1 - OOP(I) Recapped Default Constructor Default Constructor public class Tool { private int le...
View Full Document

Ask a homework question - tutors are online