.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Test abstract class

Posted By:SanthoshNathan       Posted Date: November 02, 2010    Points: 15    Category: Visual Studio    URL: http://www.dotnetspark.com  

Test abstract class
 

using System;

 abstract class Window
 {
     // constructor takes two integers to
     // fix location on the console
     public Window(int top, int left)
     {
         this.top = top;
         this.left = left;
     }

     // simulates drawing the window
     // notice: no implementation
     abstract public void DrawWindow();

     protected int top;
     protected int left;

 }

 // ListBox derives from Window
 class ListBox : Window
 {
     // constructor adds a parameter
     public ListBox(
         int top,
         int left,
         string contents):
         base(top, left)  // call base constructor
     {

         listBoxContents = contents;
     }

     // an overridden version implementing the
     // abstract method
     public override void DrawWindow()
     {

         Console.WriteLine ("Writing string to the listbox: {0}",
             listBoxContents);
     }

     private string listBoxContents;  // new member variable
 }

 class Button : Window
 {
     public Button(
         int top,
         int left):
         base(top, left)
     {
     }

     // implement the abstract method
     public override void DrawWindow()
     {
         Console.WriteLine("Drawing a button at {0}, {1}\n",
             top, left);
     }

 }

 public class TesterAbstractClass
 {
     static void Main()
     {
         Window[] winArray = new Window[3];
         winArray[0new ListBox(1,2,"First List Box");
         winArray[1new ListBox(3,4,"Second List Box");
         winArray[2new Button(5,6);

         for (int i = 0;i < 3; i++)
         {
             winArray[i].DrawWindow();
         }
     }
 }


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend