We help IT Professionals succeed at work.

Must Classes Be Instantiated?

deleyd
deleyd asked
on
359 Views
Last Modified: 2012-05-11
If I have a class which has only methods in it, do I still need to instantiate the class first before I can call one of the methods?

Is there a way to avoid this and still have other code in other files? (I come from the old fashioned old world of non-OOP programming and assembly language.)

What happens internally behind the scenes when I instantiate a class of this form? What happens if I instantiate more than one copy of a class which only contains code? Does it make separate copies of the code, or is it somehow smart to know it doesn't need to do that?

class MyProcs
{
    public DoStuff()
    {
       ...code...
    }
}

class program
{
    static void Main()
    {
        MyProcs x = new MyProcs()    // Do I have to do this just to run code?
        x.DoStuff()
    }

Open in new window

Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Paul JacksonSoftware Engineer
CERTIFIED EXPERT
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.