3.14. Test Your Understanding

 < Day Day Up > 


What type of class cannot be inherited?


How many classes can a class directly inherit? How many interfaces?


Referring to the following class, answer the questions below:

 public class ShowName {    public static void ShowMe(string MyName)    { Console.WriteLine(MyName); } } 

  1. Can the method ShowName be referenced from s?

     ShowName s = new ShowName(); s.ShowMe("Giacomo"); 

  2. Write a code sample that will print "My Name is Ishmael".


Can an abstract class have non-abstract methods?


What keyword must a derived class use to replace a non-virtual inherited method?


What are the results from running the following code?

 public class ParmTest {    public static void GetCoordinates(ref int x, int y)    {       x= x+y;       y= y+x;    } } // calling method int x=20; int y=40; ParmTest.GetCoordinates(ref x, y); Console.WriteLine("x="+x+" y="+y); 

  1.  x=60 y=40 

  2.  x=20 y=60 

  3.  x=20 y=40 

  4.  x=60 y=60 


What is the best way to ensure that languages that do not recognize operator overloading can access C# code containing this feature?


Name two ways that you can prevent a class from being instantiated.


Your application contains a class StoreSales that fires an event when an item is sold. The event provides the saleprice (decimal), date (DateTime), and the itemnum (int) to its subscribers. Create an event handler that processes the ItemSold event by extracting and printing the sales data.

 public delegate void SaleDelegate(object sender,                                   SaleEvArgs e); public event SaleDelegate ItemSold; StoreSales mysale= new StoreSale(); mySale.ItemSold += new SaleDelegate(PrintSale); 


What happens if you attempt to compile and run the following code?

 using System; public class Base {    public void aMethod(int i, String s)    {       Console.WriteLine("Base Method");    }    public Base()    {       Console.WriteLine("Base Constructor");    } } public class Child: Base {    string parm="Hello";    public static void Main(String[] argv)    {       Child c = new Child();       c.aMethod();    }    void aMethod(int i, string Parm)   {       Console.WriteLine(Parm);    }    public void aMethod()    { } } 

  1. Error during compilation.

  2. "Base Constructor" is printed.

  3. "Base Constructor" and "Base Method" are printed.

  4. "Base Constructor" and "Hello" are printed.

     < Day Day Up > 

    Core C# and  .NET
    Core C# and .NET
    ISBN: 131472275
    EAN: N/A
    Year: 2005
    Pages: 219

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net