What is a class and package in Java ? Explain difference between them

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

In object-oriented programming, a class is a programming language construct that is used to group related instance variables and methods. Each class expresses structural and behavioral design decisions made by the programmer to indicate what types of objects can exist when the program is executed.
A class is a cohesive container that consists of a particular […]

Read the rest of this entry »

What is inheritance in Java ?

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Inheritance is feature of object oriented programming which allows to extend existing types it defines “is-a” relationship (ex. Triangle extends Shape means that Triangle “is-a” Shape).
Inheritance is an integral part of Java (and all OOP languages). It turns out that you’re always doing inheritance when you create a class, because unless you explicitly inherit from […]

Read the rest of this entry »

Give differences between early binding and late binding in Java ?

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Connecting a method call(i.e. Function Call) to a method body(i.e. Function) is called binding.
When binding is performed before the program is run (by the compiler and linker, if there is one), it’s called early binding. You might not have heard the term before because it has never been an option with procedural languages. C compilers […]

Read the rest of this entry »

What are the advantages of polymorphism in Java ?

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Polymorphism is the third essential feature of an object-oriented programming language, after data abstraction and inheritance. I have seen lot’s of people NOT clear with what polymorphism is or they often stumble when somene ask them to explain, so be very sure what it is.
Just remember this - Poly means Multiple and Morphe means types […]

Read the rest of this entry »

Explain the differences between interface and class in Java

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Interface has no implementation where class provides implementation for interface (its own or some external; if class implements one it has to provide implementation for it)
This is very very important questions and probably the first Java question that will be asked to your by interviewer.

Read the rest of this entry »

How many interfaces can be implemented by one class in Java

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Infinite if return types of same methods are the same.
Because interface has no implementation there is no risk that Java virtual machine will not know which implementation choose to run. Such problem occurs when language allows You to extend more than one class. When You inherit from more than one implementations (classes) there is a […]

Read the rest of this entry »

How many interfaces can be extended by one interface in Java

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Infinite if return types of same named are the same. Look Previoous Question for explaination

Read the rest of this entry »

Do (not static) inner classes have access to private members of outer class in Java

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

Yes. Example:
public class Outer {
private String dontTouch = “my secret private String”;
class Innter() {
public String revealSecret() {
return dontTouch;
}
}
public static void main(String args, String[] argv) {
Outer outer = new Outer();
Outer.Innter inner = outer.new Inner();
System.out.println(inner.revealSecret());
}
}
When You run above example program You will see: “my secret private String” on console output.

Read the rest of this entry »

Which members of outer class are accessible within inner class in Java

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

All: public, private, protected and default.

Read the rest of this entry »

What are the difference between Set and List.in Java ?

October 28, 2007 · Filed Under Java SE Interview questions, Placement Questions

The Java 2 container library takes the issue of “holding your objects” and divides it into two distinct concepts:
1. Collection: a group of individual elements, often with some rule applied to them. A List must hold the elements in a particular sequence, and a Set cannot have any duplicate elements. (A bag, which is not […]

Read the rest of this entry »