Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Core Java Interview Questions List: Part III

DZone's Guide to

Core Java Interview Questions List: Part III

Can a constructor ever be final? What does final actually do? These are just a few of the questions in this core Java interview questions brush up session.

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

The name of the game is core java interview questions and I will be your quiz master. Each week I will publish 10 new quick fire questions and answers.

1. Can you overload the main method?

Absolutely.  However, the JVM will only use the standard main(String[] args) when launching.

2. What is a marker interface?

A Marker interface is an interface with no methods on it, used only as an indicator.  Serializable and Clonable are examples in the JDK.

3. Can a constructor be final?

Nope.

4. What does applying final actually do?

Applying final to a variable means the variable cannot be changed.

Applying final to method means they can be overridden.

Applying final to a class means the class cannot be overridden

5. What is an anonymous inner class?

It is possible to create the implementation of an interface in line. Syntactically, it looks like we are instantiating a new instance of an interface.

MyInterface interface = new MyInterface(){
   public void aMethod(){

   }
}

It is called anonymous because it cannot be referenced elsewhere.  It literally has no name.

6. What is casting in Java?

Casting is the act of turning one object into another.  We can refer to an Integer as an Integer, or upcast it to an Object.  It is an upcast as it is higher in the inheritance hierarchy. Alternatively, if we cast the other way from an Object to an Integer, we are downcasting.  We must be careful when casting as, if the object cast is invalid it will throw a ClassCastException.

7. Can we override an overloaded method?

Yes! Of course.  They are two orthogonal concepts.

8. What is a transient variable?

When a variable is marked transient it will not be serialized.

9. What is the difference between while and do while?

A while loop is not guaranteed to run; if the condition is false then the code in the loop will not be executed.  A do while is guaranteed to execute once.

10. What does the % operator do?

% is the modulus operator.  It will give the remainder of a division. For example, in 11 / 2, the result is 5. 11%2 will provide the remainder, which is 1.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:
java ,interview

Published at DZone with permission of Sam Atkinson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}