C# classes quesitons

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    C# classes quesitons

    1. Can an abstract class have some implementation (say default
    assuming derived chooses not to implement it)?

    2. Does CSharp has a concept of inner class comparable to java's,
    where inner class can reference into wrapping class?

    3. How is virtual, and polymorphism in general, is implemented?


    Thanks

  • Duggi

    #2
    Re: C# classes quesitons

    On Sep 30, 8:13 am, puzzlecracker <ironsel2...@gm ail.comwrote:
    1. Can an abstract class have some implementation (say default
    assuming derived chooses not to implement it)?
    >
    2. Does CSharp has a concept of inner class comparable to java's,
    where inner class can reference into wrapping class?
    >
    3. How is virtual, and polymorphism in general,  is implemented?
    >
    Thanks
    1. Can an abstract class have some implementation (say default
    assuming derived chooses not to implement it)?
    Abstract class can have implementation for some of the methods. If a
    class that is derived from an abstract class, chooses not to override
    the abstract method, the class should be abstract again.
    2. Does CSharp has a concept of inner class comparable to java's,
    where inner class can reference into wrapping class?
    If you mean class declared with in another class, Yes, it is
    supported.
    3. How is virtual, and polymorphism in general, is implemented?
    it is implemented with the virtual and override keywords.




    explains the ovverride concept in C#

    -Cnu




    Comment

    • Peter Duniho

      #3
      Re: C# classes quesitons

      On Mon, 29 Sep 2008 20:13:47 -0700, puzzlecracker <ironsel2000@gm ail.com>
      wrote:
      1. Can an abstract class have some implementation (say default
      assuming derived chooses not to implement it)?
      Yes. Though, given your previous question a week ago ("If we implement
      methods in abstract class, do we still need to
      declare them as abstract"), I have no idea why you don't already know the
      answer to this one.
      2. Does CSharp has a concept of inner class comparable to java's,
      where inner class can reference into wrapping class?
      No. You can have nested classes in C#, but they are related only with
      respect to accessibility of the outer class members. There's no implicit
      reference to any specific instance of the outer class (i.e. they are like
      Java's static nested classes).
      3. How is virtual, and polymorphism in general, is implemented?
      Define "implemente d". Are you asking what the actual underlying
      implementation is when you use virtual methods or interfaces? If so, the
      basic answer is that it's similar to how C++ does it, with a v-table.

      Pete

      Comment

      • Alex Meleta

        #4
        Re: C# classes quesitons

        Hi puzzlecracker,
        1. Can an abstract class have some implementation (say default assuming
        derived chooses not to implement it)?
        the best way to remember the difference is first of all it's a class, and
        only then it's abstract. So, as a class it has implementation, but, because
        it's abstract it cannot be instantiated.

        Regards, Alex Meleta
        [TechBlog] http://devkids.blogspot.com
        1. Can an abstract class have some implementation (say default
        assuming derived chooses not to implement it)?
        >
        2. Does CSharp has a concept of inner class comparable to java's,
        where inner class can reference into wrapping class?
        >
        3. How is virtual, and polymorphism in general, is implemented?
        >
        Thanks
        >

        Comment

        Working...