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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:50:50+00:00 2026-05-16T05:50:50+00:00

Can I create instance of abstract class in C#/.net like in Java ? Additional

  • 0

Can I create instance of abstract class in C#/.net like in Java ?

Additional Info

I think a lot of us does not understand what do I mean?
So, In java I can create abstract class like this :

Simple abstract class :

/**
 * @author jitm
 * @version 0.1
 */
public abstract class TestAbstract
{
    public abstract void toDoSmth();
}

Code where I’ve create instance of abstract class

/**
 * @author jitm
 * @version 0.1
 */
public class Main {
    public static void main(String[] args) {
        TestAbstract testAbstract = new TestAbstract() {
            @Override
            public void toDoSmth() {
                System.out.println("Call method toDoSmth");
            }
        };
    }
}

Can I to do in c# something like this ?

  • 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-05-16T05:50:51+00:00Added an answer on May 16, 2026 at 5:50 am

    Neither in Java nor in C# you can create an instance of an abstract class.
    You will always need to create a concrete class that inherits from the abstract class.
    Java lets you do it without naming the class, using anonymous classes. C# does not give you that option.

    (Edited to show a delegate as a replacement. I don’t have access to VS here, so it may not compile, but this is the idea )

    Usually in Java when you use an abstract class with a single abstract method (SAM) what you are really trying to achieve is to pass some code as a parameter.
    Let’s say you need to sort an array of objects based on the class name, using Collections.sort(Collection, Comparator)
    (I know Comparator is an interface, but it is the same idea)
    Using an anonymous class to avoid extra typing, you can write something like

       Comparator<Object> comparator = new Comparator<Object>{
            @Override
            public int compare(Object o1, Objecto2) {
                return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()));
            }//I'm not checking for null for simplicity
       } 
       Collections.sort(list, comparator)
    

    In C# 2.0 and beyond you can do pretty much the same using the Comparison<T> delegate. A delegate can be thought as a function object, or in java words, a class with a single method. You don’t even need to create a class, but only a method using the keyword delegate.

    Comparison<Object> comparison = delegate(Object o1, Object o2)
    {
        return o1.class.Name.CompareTo(o2.class.Name);        
    };
    
    list.sort(comparison);
    

    In C# 3.0 and beyond you can write even less code using lambdas and type inference:

    list.sort((o1, o2) => o1.class.Name.CompareTo(o2.class.Name))
    

    Anyway, if you are migrating code form java to c# you should read about delegates…in many of cases you will use delegates instead of anonymous classes. In your case, you are using a method void toDoSmth(). There is a delegate called Action which is pretty much the same thing, a method with no parameters and no return.

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

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ISO 8601 all the way Using any epoch-based method means… May 16, 2026 at 11:51 am
  • Editorial Team
    Editorial Team added an answer Are you using onKeyUp()? Use just onKeyDown() in Android 1.x… May 16, 2026 at 11:51 am
  • Editorial Team
    Editorial Team added an answer In fact, CGI does uses STDIN. It is used to… May 16, 2026 at 11:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am developing a couple of small ASP.NET application and would like to know
At the moment I'm trying to create a kind of model in vb.net which
I'm looking at a VB.NET class (that I didn't write) that is declared MustInherit
I want to raise an event from a .NET class, and receive this event
Anyone know how I can dynamically load a control inside of a shared/static function?
I'm writing a plugin for an application with a .NET API. The objects of
What is the difference between a class with protected constructors and a class marked
I am relatively new to C#/.Net. I'm developing a desktop application that requires multi
I have a class Wizard which creates a wizard with pages defined in the
I am trying to reproduce something that System.Xml.Serialization already does, but for a different

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.