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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:47:43+00:00 2026-06-05T19:47:43+00:00

I have a job interview tomorrow and I’m trying to answer this question: There

  • 0

I have a job interview tomorrow and I’m trying to answer this question:

There is a class named C and method m in this class, this class have also empty constructor:

Main ()
{
C c = new c();

}

Class C {

public c {

//empty constructor

}

public m {

//does something - doesnt mind

}

} 

And what you have to do is to change the code so that in a creation of an instance class C, the method m would be called before the class constructor.

You have to do this without changing the main (edit only the class code).

Thanks in advance!

  • 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-05T19:47:45+00:00Added an answer on June 5, 2026 at 7:47 pm

    Like the other answers have said, you can make the method static. But then you need to explicitly call it. If you make a static class constructor, that will get called once automatically (you don’t need to call it), the first time the class is referenced (like when you construct the first instance). You can’t exactly control when it executes, but it will execute before the first instance is constructed. Based on the way they’ve worded the question (you can’t change the Main method), I think static class constructor is the answer they’re looking for.

    http://msdn.microsoft.com/en-us/library/k9x6w0hc%28v=vs.80%29.aspx

    Static constructors have the following properties:
    A static constructor does not take access modifiers or have parameters.
    A static constructor is called automatically to initialize the class before the first instance is created or any static members are
    referenced.
    A static constructor cannot be called directly.
    The user has no control on when the static constructor is executed in the program.

    Java doesn’t have static class constructors, but they do have static initialization blocks..

    static {
        // code in here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm unemployed and I have a job interview tomorrow where knowledge about Websphere 5.x
I have a job interview late next week as a report developer. At this
I was asked this question in a .net/C# interview: If we have two threads
Introduction: So, I have an interview tomorrow and I'm trying to review SQL and
I have a job interview tomorrow for a .NET shop. For the past few
I was asked this question in a job interview. The interviewer and I disagreed
I was given this question at a job interview recently and couldn't figure out
I have a job that must execute each monday. This job run in a
I have a job interview coming that will focus on T-SQL and general SQL
I have been asked recently in a job interview to develop an algorithm that

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.