Interview Question for Software Engineer / Developers

Country: Netherlands

Comment hidden because of low score. Click to expand.
of 5 vote


SM : When a method declaration includes a static modifier, that method is said to be a static method.
IM : When no static modifier is present, the method is said to be an instance method.

SM : Static method is the only one. All the instances will be accessing the same method
IM : Every instance of the class will have its own instance methods

static members as belonging to classes
Instance members as belonging to objects (instances of classes).

SM : When a static member M is referenced in a member-access of the form E.M, E must denote a type containing M.It is a compile-time error for E to denote an instance.
IM : When an instance member M is referenced in a member-accessof the form E.M, E must denote an instance of a type containing M. It is a compile-time error for E to denote a type.

SM : Static methods just operate on input parameters and cannot access internal instance fields.
IM : Instance method can acces the instance fields

SM : The static method is callable on a class even when no instance of the class has been created.
IM : Cannot access instance method with out the instance

SM : Static methods cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
IM : Instance methods can access static fields

SM : Static methods can be overloaded but not overridden
IM : Instance methods can be overriden when the class containing the instance method is inherited and having virtual keyword in the base class method and overriden key word in the derived class method

SM : A call to a static method generates a call instruction in Microsoft intermediate language (MSIL)
IM : call to an instance method generates a callvirt instruction, which also checks for a null object references

Example :

class Test
{ static void Main() {
int x; Test t = new Test();
static int y; t.x = 1; // Ok
void F() { t.y = 1; // Error, cannot access static member through instance
x = 1; // Ok, same as this.x = 1 Test.x = 1; // Error, cannot access instance member through type
y = 1; // Ok, same as Test.y = 1 Test.y = 1; // Ok
} }
static void G() { }
x = 1; // Error, cannot access this.x
y = 1; // Ok, same as Test.y = 1

Source : msdn

- karthiga.m1988 February 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 3 vote

Just to add to this regarding locks..
When you synchronize a static method.. the thread that enters the method holds the class level lock
And when you synchronize a non static method.. the thread that enters the method holds the lock on the object of the class

- Amit March 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

In object oriented languages, you can create instances of classes (instance objects) in you have access to instance methods. The instance methods are defined within the class that instance object represents.

Depending on the programming language, you can have static class methods that can be called outside the context of an instance, however those methods cannot use the "this" keyword since there is no instance that you can reference within the method.

- Anonymous February 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Instances methods are those methods which are called using the objects of the class while there are static methods in class as well which can be called without creating object of the class, just by the name of the class

- DashDash February 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Class methods (C++ terminology: static method) are available for use without a concrete object of the class.
Instance methods are available to use only when there's a concrete object that will operate this method. Also, since there is a concrete object involves, the instance function can access and modify the object's members. Class methods cannot do that, since there is no object to manipulate.

A good example of a class method is object creation. The knowledge of how to create an object in encapsulated within the class.

- Jerry K February 23, 2013 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More