Core Java Interview Questions part-2

6)  Difference between abstract class and interface ?

                  Interface                Abstract Class
1)      Interface contains only abstract methods 1)      Abstract class can contain abstract methods, concrete methods or both
2)      Access Specifiers for  methods in interface must be public 2)      Except private we can have any access specifier for methods in abstract class.
3)      Variables defined must be public , static , final 3)      Except private variables can have any access specifiers
4)      Multiple Inheritance in java is implemented using interface 4)We cannot achieve multiple inheritance using abstract class.
5)      To implement an interface we use implements keyword 5)To implement an abstract class we use extends keyword

7)      Why java is platform independent?

The most unique feature of java is platform independent. In any programming language source code is compiled in to executable code . This cannot be run across all platforms. When javac compiles a java program it generates an executable file called .class file.

class file contains byte codes. Byte codes are interpreted only by JVM’s . Since these JVM’s are made available across all platforms by Sun Microsystems, we can execute this byte code in any platform.  Byte code generated in windows environment can also be executed in linux environment. This makes java platform independent.

8)      What is method overloading in java ?

A class having two or more methods with same name but with different arguments then we say that those methods are overloaded.  Static polymorphism is achieved in java using method overloading.

Method overloading is used when we want the methods to perform similar tasks but with different inputs or values. When an overloaded method is invoked java first checks the method name, and the number of arguments ,type of arguments; based on this compiler executes this method.

Compiler decides which method to call at compile time. By using overloading static polymorphism or static binding can be achieved in java.

Note : Return type is not part of method signature. we may have methods with different return types but return type alone is not sufficient to call a method in java.

9)      What is difference between c++ and Java ?

                   Java              C++
1)      Java is platform independent  C++ is platform dependent.
2)      There are no pointers in java  There are pointers in C++.
3)      There is no operator overloading in java  C ++ has operator overloading.
4)      There is garbage collection in java  There is no garbage collection
5)      Supports multithreading Does’nt support multithreading
6)      There are no templates in java There are templates in C++.
7)      There are no global variables in java There are global variables in c++

10)   What is JIT compiler ?

JIT compiler stands for Just in time compiler. JIT compiler compiles byte code in to executable code . JIT  a part of JVM .JIT cannot convert  complete java program in to executable code it converts as and when it is needed during execution.

5 thoughts on “Core Java Interview Questions part-2

  1. Method overloading: We may have methods with different return types.

    Wrong ! We cannot have methods differing just with return types.

    • author says “do not depend on the return type, only on the signature”. That why he says “…..return type alone is not sufficient…”.

Leave a Reply

Your email address will not be published. Required fields are marked *