Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What is the difference between initiating a class and inheriting a class?</p> </blockquote> <p>First off, the word you're looking for is <strong>instantiate</strong>, not <strong>initiate</strong>. </p> <blockquote> <p>What is the difference between instantiating a class and inheriting a class?</p> </blockquote> <p><em>Inheritance</em> expresses the "is a kind of" relationship between two classes:</p> <ul> <li>The New York Times <em>is a kind of</em> newspaper.</li> <li>A giraffe <em>is a kind of</em> animal.</li> <li>An apple <em>is a kind of</em> fruit.</li> </ul> <p>In each of these cases the first kind of thing is the "more derived" type -- it is <em>more specific</em> -- and the second thing is the "less derived" type, or "base" type. It is <em>more general</em>. More things are fruits than are apples.</p> <p>In C# when you establish an inheritance relationship between two classes, you get two things:</p> <ul> <li>Assignment compatibility: you can use an expression of the more derived type where an expression of the base type is needed.</li> <li>Member inheritance: all methods, events, indexers, operators, fields, properties and nested types of the base class are automatically members of the derived class. (Constructors and destructors are not inheritable).</li> </ul> <p><em>Instantiation</em> is the process of making a new instance of a type. </p> <ul> <li>Here, let me give you a copy of today's New York Times.</li> <li>Here, let me give you a giraffe.</li> <li>Here, let me give you an apple.</li> </ul> <p>So in C#:</p> <pre><code>class Fruit {} class Apple : Fruit { } // Apple inherits from Fruit class Program { static void Main() { Apple apple = new Apple(); // Instantiating a new Apple } } </code></pre> <p>Make sense?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload