Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8291287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:04:55+00:00 2026-06-08T13:04:55+00:00

class Program { static void Main(string[] args) { Father objFather = new Son(); //Ok

  • 0
class Program
{
    static void Main(string[] args)
    {

        Father objFather = new Son(); //Ok compiles

        Son objSon1 =  new Father(); //Comile time error : Cannot implicitly convert type

        Son objSon = (Son)new Father();  //Run time error
        Console.ReadLine();
    }
}

class Father
{
    public void Read()
    {

    }

}

class Daughter:Father
{

}

class Son:Father
{

}

Can anybody Explain why it is? And what is happening in memory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:04:56+00:00Added an answer on June 8, 2026 at 1:04 pm

    You seem to misunderstand inheritance.

    Every Daughter and every Son is a Father. That’s why you can safely assign both to a Father variable. A subclass can’t remove attributes/methods only add them, that’s why it’s sure it’s always working.

    But when you have an instance of Father and want to assign it to a Son variable, you can’t be sure that the instance is a Son and actually has all the properties needed. The Father instance could as well contain a Daughter which is not compatible to Son. That’s why the compiler can’t implicitly convert them but you as a programmer can explicitly do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
I have the following code: class Program { static void Main(string[] args) { new
class Program { static void Main(string[] args) { var x = new Program(); Console.Write(x.Text);
class Program { static void Main(string[] args) { A a = new A(); a.print();
class Program { static void Main(string[] args) { var dictionary = new Dictionary<string, int>()
class Program { static void Main(string[] args) { var getfiles = new fileshare.Program(); string
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine(new
class Program { static void Main(string[] args) { List<A> myList = new List<A> {new
class Program { static void Main(string[] args) { baseClass obj = new baseClass(); obj.intF
class Program { static void Main(string[] args) { Func<Object> someMethod = new Func<Object>(((Object)null).ToString); String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.