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

  • SEARCH
  • Home
  • 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 9005543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:10:24+00:00 2026-06-16T01:10:24+00:00

I have a shape class with square and triangle as inheriting classes Square square

  • 0

I have a shape class with square and triangle as inheriting classes

Square square = new Square();
square.SideCount = 4;
//Logic
square.SideCount = 3;
 
if(square is Triangle)
   {
   //...

If I instantiate a new square with SideCount = 4, then if I change it’s SideCount to 3, can I put code into the SideCount’s Setter to convert Square to Triangle if sides are set to 3?

  • 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-16T01:10:25+00:00Added an answer on June 16, 2026 at 1:10 am

    Not directly no, an instance of Square cannot be changed to an instance of Triangle.

    You could have a method, which returns an instance of Shape defined on the base class Shape:

    public abstract class Shape
    {
        public Shape Mutate(int numberOfSides)
        {
            // over simplified example:
            if(numberOfSides == 3)
               return new Triangle();
        }
    }
    
    public class Triangle : Shape {}
    public class Square : Shape {}
    

    usage

    var squ = new Square();
    var triangle = squ.Mutate(3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a superclass Shape, and classes Triangle, Square, etc. extend Shape. I have
I have a base class Shape , and other derived classes Circle , Square
You can have a super class Shape, Square and Rectangle are two children class,
Let's say we already have a hierarchy of classes, e.g. class Shape { virtual
Let's say I have an enumeration. enum class ShapeName : char {TRIANGLE,CIRCLE,SQUARE}; and later
I have a Shape class containing potentially many vertices, and I was contemplating making
Let me explain you my situation. I have a base class called Shape, and
In Python, say I have some class, Circle, that inherits from Shape. Shape needs
I have a shape in Visio which is a group. The group shape can
In C#, I have a class hierarchy with a couple of abstract base classes

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.