Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Demo
- {
- class A
- {
- public A()
- {
- System.Console.WriteLine("This is a {0},", this.GetType());
- }
- }
- class B : A
- {
- }
- // . . .
- B b = new B(); // Output: "This is a Demo.B"
- }
- class Parent
- {
- public Parent()
- {
- DoSomething();
- }
- protected virtual void DoSomething() {};
- }
- class Child : Parent
- {
- private string foo;
- public Child() { foo = "HELLO"; }
- protected override void DoSomething()
- {
- Console.WriteLine(foo.ToLower());
- }
- }
- class B
- {
- protected virtual void Foo() { }
- }
- class A : B
- {
- public A()
- {
- Foo(); // warning here
- }
- }
- sealed class A : B
- {
- public A()
- {
- Foo(); // no warning
- }
- }
- class A : B
- {
- public A()
- {
- Foo(); // no warning
- }
- protected sealed override void Foo()
- {
- base.Foo();
- }
- }
Add Comment
Please, Sign In to add comment