Java is a fun language. Some of the reasons to use it are: Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection). Object Oriented (OO). Better portability than other languages across operating systems. Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI, EJB etc) and network protocols (HTTP, JRMP […]
Category: Java Interview questions
How are this() and super() used with constructors?
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
What restrictions are placed on method overloading?
Two methods may not have the same name and argument list but different return types.
How are parameters passed in Java, by value or by reference?
By value but in the case of objects, the value is a reference.
How do you call a method in a super class from a subclass?
Use the super keyword like so: super.someMethodCall(“some string parameter” ); Note that in most cases the super keyword may be omitted.
How do you call a constructor of a super class? Where would you call it?
A call to the default super class constructor is implicitly the first line of each constructor unless a different constructor is explicitly provided by the developer. So for the first line of a constructor that calls a non-default super class constructor, one might write: super(“some string”); It’s a compilation error if it is not the […]
Where would you use the keyword extends and implements?
extends is the keyword used to declare that this class is a subclass of the class that follows the extends keyword. Implements is a keyword that designates this class as an implementer of the specified interface.
What is an abstract class?
An abstract class is a class declared with the abstract keyword. Although references to such a class may be used, the class may not be directly instantiated. Abstract classes may define methods or just declare them and may contain variables.
What are the four types of nested classes?
1. static nested class 2. inner (non-static) nested class 3. local class 4. anonymous class A static nested class is just like a normal Java class. If it is public, it can be accessed or used to create objects just like any other class. A non-static inner class requires an object of the containing class. […]
Why would you declare a class final?
Making a class final adds some security and consistency to the class behaviour. E.g. by making the String class final, you cannot override its length method. The compiler may optimize the code and make it run faster when a class is declared final.