Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Answer to this interview question

I came across this site and it has the answer to the questions. I want to know why the answers are that.

   public class A
        {
            public A()
            {
                var p = "In A";
            }

            static A()
            {
                var p = "in Static A";
            }

            public void Method()
            {
                var p = "In Method A";
            }

        }



        public class B:A
        {
            public B()
            {
                var p = "In B";
            }

            static B()
            {
                var p = "in Static B";
            }

            public void Method()
            {
                var p = "In Method B";
            }

        }

Open in new window


1. A a = new A();  -- Why does it call the "In static A" first and then "In A"?  Static methods can't be called with "new"

2. B b = new A();  -- why is this an error? B inherits from A

3. A c = new B();  -- this calls "in static B" first, then "in Static A", then "In A" and then "In B".  Same as #1. Why is it calling "static" method first?  It inherits from A ...that's why it calls "in Static A", then "In A" next, correct?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fancy stuff?  These are examples to help people understand how principles of OOP work...
yes but, even most experienced people will not be able to answer it correctly without putting some debugs statements or debugging it :)
I guess that's a matter of opinion.  The examples and questions seemed pretty straightforward to me.
Avatar of Camillia

ASKER

I totally agree with HainKurt. Now, why am I reviewing interview questions. I have a dilemma that I want advice on...

I've been at my current job for 8 months. I had a phone technical interview. Then I went in for an in-person interview and I had a written test.  I got the job as a contractor. I missed maybe 3 or 4 questions.

Now, the team wants to hire a perm position because they fired someone.  I was told I'll be having a tech interview. They said it's the process. They already know me, and my work.

Can I decline to take a tech interview test? should I say I've already taken the test? I'm not desperate for a perm position but they do have fantastic benefits.

I'm 99% leaning towards saying no to the tech interview process.
They may have to administer the test to all applicants for HR reasons (i.e. so no one can claim they were not evaluated on an even playing field).  I don't know... I'm not an HR generalist.

However, I have been through a good number of interviews, and in many cases, I did the interviews purely for the experience so that when my "dream job" came along, I was prepared for what could come my way in the interview.

I hate interviews that require you to write code on a white board while you stand in front of the interviewers.  That is not something developers usually do when they're working.  But it's a "test" that many interviewers will throw out there because it helps to narrow the focus on people who have studied and prepared themselves.  Some employers are not just looking for someone who can do a job.  They want someone who will excel at a job and bring something to the table that other applicants may not be able to bring.

So.. again, totally my opinion ... any challenge or test that you're offered as part of an interview process should be taken as an opportunity to show how you're the best choice.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial