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 8359693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:13:50+00:00 2026-06-09T11:13:50+00:00

Consider the following very basic C# code. using System; using System.Collections.Generic; using System.Linq; using

  • 0

Consider the following very basic C# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();

            for (int i = 1; i <= 100; i++)
            {
                int num = random.Next(1000);
                string it_type;

                if (num == 666)
                {
                    System.Console.Write("Antichrist/satanistic trips get. Enjoy! ");
                    JonSkeet technician = new JonSkeet(); // Needs more Super::$tatic
                    technician.setup();
                    it_type = technician.getITType();
                }
                else
                {
                    Whisperity technician = new Whisperity();
                    technician.setup();
                    it_type = technician.getITType();
                }

                System.Console.WriteLine(it_type + "... Prepare for next iteration.");
            }

            System.Console.ReadLine();
        }
    }

    abstract public class ITTechnician
    {
        protected string itt_type = "Noname person.";
        protected bool isJonSkeet = false;

        public string getITType()
        {
            return this.itt_type;
        }

        abstract public void setup();
    }

    public class JonSkeet : ITTechnician
    {
        public override void setup()
        {
            this.itt_type = "Jon Skeet";
            this.isJonSkeet = true;
        }
    }

    public class Whisperity : ITTechnician
    {
        public override void setup()
        {
            this.itt_type = "Whisperity";
            this.isJonSkeet = false;
        }
    }
}

How would I be able to set up a constructor in a way that the abstract class (abstract public void?) would require it and that I don’t have to call technician.setup(); because the constructor takes care of setting the two internal variables. If I call the class functions the same name as the class itself, I get the following error:

Error 1 ‘Whisperity’: member names cannot be the same as their enclosing

Also, my other question would be about optimization. Is there a way to define technician outside the if construct so something like the following could be executed: (This would omit having the classType technician = new classType(); lines twice, or is it unbypassable in C#?)

string it_type;
// Register 'technician' as a variable here.
if (num = 666)
{
    technician = new JonSkeet();
}
else
{
    technician = new Whisperity();
}

it_type = technician.getITType();
System.Console.WriteLine(it_type + "...");
  • 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-09T11:13:52+00:00Added an answer on June 9, 2026 at 11:13 am

    Answer to your Question

    You can provide a constructor with parameters in the abstract class.

    abstract public class ITTechnician
    {
        public ITTechnician(string itt_type, bool isJonSkeet)
        {
            this.itt_type = itt_type;
            this.isJonSkeet = isJonSkeet;
        }
    }
    

    To construct a JonSkeet (if only it were so easy!)

    JonSkeet jon = new JonSkeet("Jon Skeet", true);
    

    Advice on Class Design

    On a side note, I know this is a sample question, but you are not using object orientation well if a base class holds information that would differentiate classes that inherit from it.

    Specifically this design would lead you to do things like

    ITTechnician itt = GetSomeInstance();
    
    if (itt.IsJonSkeet)
    {
        BehaviorA();
    else
    {
        BehaviorB();
    }
    

    It is far cleaner to do something like

    abstract public class ITTechnician
    {
        public abstract void Behavior();
        // ...
    }
    
    public class JonSkeet
    {
        public override Behavior()
        {
            // Do awesome things
        }
    }
    

    which allows the above code to be written as

    ITTechnician itt = GetSomeInstance();
    itt.Behavior();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: namespace DisposeTest { using System; class Program { static void
Consider the following code: using System; using System.Runtime.InteropServices; namespace Demo { class Program {
Consider the following code: namespace ConsoleApplication { using NamespaceOne; using NamespaceTwo; class Program {
This is a very basic question, so please bear with me. Consider the following
Consider the following code: class B { int x; public: B() : x( 10
Consider the following code: <html> <head></head> <body> <div id='test' class='blah'> <a href='http://somesite.com/' id='someLink'>click!</a> </div>
Consider the following very basic WCF service implementation: public enum TransactionStatus { Success =
Consider the following two statements out of a very simple assembly language program: DATA1
Consider the following code: class A { B* b; // an A object owns
I know, this is very simple for you guys. Please consider the following code:

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.