Core Java Interview Questions

Showing Questions 1 - 20 of 587 Questions
First | Prev | Next | Last Page
Sort by: 
Jump to Page:

    Why we can not override static method?


    • Feb 4th, 2016

    If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the superclass. You didn't override the method a(), because static methods are not inherited. If you had put @Override, you would have seen an error.


    • Nov 4th, 2015

    We can override the static method, generally in real time we are not doing this. e,g "c public class X { public static void m1(int i){ System.out.println("X static "); } } public...


    String Format Expression

    In the expression String.format("%2d", 5)
    what are the things below, be specific. for example, if the thing is an operator, indicate whether it is binary/unary and whether it is arithmetic/logical/relational. If it is a method, indicate whether its static or not

    a. String
    b. .
    c. format()
    d. "%2d" and 5


    Can we declare main() as final?


    • Jan 25th, 2016

    We can declare main() as final but it will not be the "main" that JVM will be searching. since JVM search for "public static void main(string[] args)" so if you will put anything extra in this syntax then JVM will not be able to find the main method and it will give run time exception.


    • Sep 29th, 2015

    Smarti please check your JDK version. Your answer is depends on your version. If you have JDK 1.8 then it will show compile time exception else your program get compile as you compiled.
    Hope you got your answer.


    Can we override the main method?

    Star Read Best Answer

    Editorial / Best Answer


    • Member Since Oct-2006 | Oct 3rd, 2006

    check out this example

    class Checkmain{
    public static void main(String args[]){
    System.out.println("hello ");
    class Checkmain1 extends Checkmain{
    public static void main(String args[]){
    System.out.println("how r u");

    class Jo{
    public static void main(String args[]){
    String S[]=new String[10] ;



    • Jan 25th, 2016

    First thing main is Static method and for static method there is no overriding rather there is method hiding.
    so we cannot override main method


    • Jan 8th, 2016

    Suraj20p is right. Ideally we cant override main simply because its a static method.


    Why can't we create object for an abstract class?

    Naveen Kumar K R

    • Jan 17th, 2016

    In this case JVM does not know how much memory it has to allocate for that abstract method, because abstract method does not have any implementation. So JVM will not be able to allocate memory for that abstract method

    ambarish upadhyay

    • Aug 7th, 2015

    We cannot create object in abstract class because when we can compile the abstract class the compiler create them incomplete so in the abstract class we cannot create object


    Need of Polymorphism

    What is need of polymorphism in Java? What could have happen if polymorphism is not present?

    Star Read Best Answer

    Editorial / Best Answer


    • Member Since Mar-2010 | Apr 8th, 2010

    Polymorphism in simple terms means one name many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation.

    Polymorphism exists in three distinct forms in Java:
    • Method overloading
    • Method overriding through inheritance
    • Method overriding through the Java interface

    Ajas Mohammed

    • Jan 13th, 2016

    This is method overloading. Polymorphism enables method overriding not overloading. Method overriding means use of same method with same name, parameters and return type.


    • Sep 26th, 2012

    Jdbc,servlets,jsp have come through polymorphism,if not there we have to remember all dependent classes related to DB, use in our java coding


    What is the difference between abstract class & Final class

    krishna singh

    • Dec 27th, 2015

    No Class cannot be abstract and final both at a same time


    • Sep 7th, 2015

    Abstract is a class that have abstract method as well as concrete methods. An abstract class can also only have concrete methods. An abstract class can be inherited by one class only. Final class is a class that cannot be inherited.


    If there are multiple If-else, what is the alternative algorthim we can use apart from using switch?


    • Feb 14th, 2013

    I think switch case is better alternative instead of more if-else statements owing that another alternative ternary operator it would be complicated and a little bit of confusion thats why, I would prefer to go for switch case.


    What is the use of interface in realtime java project ?


    • Dec 24th, 2015

    So interfaces could be used if only if you are sure that the API will not be changed, because when you want to add some new method headings in interface you will have to change all the classes which i...


    • Dec 2nd, 2015

    Interfaces are used more like contracts that enforce the user to implement features so that you can develop a functionality knowing the person who is going to use the API will always implement certain methods are parameters as you expect. And like others said it makes multiple inheritance possible.


    What is difference between array & arraylist?

    Arraylist is resizable where as using array it is not possible.


    • Dec 24th, 2015

    First difference: array is already with fixed size while array lists size could be dynamically changed.

    Secondly, array can include only the same type of data while array list can consist of different primitive data types as well as objects.


    • Nov 18th, 2015

    Array is collection of similar data type values. We cant resizable and growable of array. It is already fixed when you declared while array list works as a dynamic in which size could be grow. It is a part of collection framework to handle or store the collection of object not any type of values.


    What is MVC architecture

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Mitchel K

    • Jun 27th, 2005

    A design pattern describes a proven solution to a recurring design problem, placing particular emphasis on the context and forces surrounding the problem, and the consequences and impact of the solution.  
    There are many good reasons to use design patterns. Here are three: 
    1) They are proven. You tap the experience, knowledge and insights of developers who have used these patterns successfully in their own work. 
    2) They are reusable. When a problem recurs, you don't have to invent a new solution; you follow the pattern and adapt it as necessary. 
    3) They are expressive. Design patterns provide a common vocabulary of solutions, which you can use to express larger solutions succinctly. 
    The goal of the MVC design pattern is to separate the application object (model) from the way it is represented to the user (view) from the way in which the user controls it (controller).  
    The MVC architecture has the following benefits: 
    1) Multiple views using the same model: The separation of model and view allows multiple views to use the same enterprise model. Consequently, an enterprise application's model components are easier to implement, test, and maintain, since all access to the model goes through these components. 
    2) Easier support for new types of clients: To support a new type of client, you simply write a view and controller for it and wire them into the existing enterprise model. 
    3) Clarity of design: By glancing at the model's public method list, it should be easy to understand how to control the model's behavior. When designing the application, this trait makes the entire program easier to implement and maintain. 
    4) Efficient modularity: of the design allows any of the components to be swapped in and out as the user or programmer desires - even the model! Changes to one aspect of the program aren't coupled to other aspects, eliminating many nasty debugging situations. Also, development of the various components can progress in parallel, once the interface between the components is clearly defined.  
    5) Ease of growth: Controllers and views can grow as the model grows; and older versions of the views and controllers can still be used as long as a common interface is maintained.  
    6) Distributable: With a couple of proxies one can easily distribute any MVC application by only altering the startup method of the application.


    • Dec 2nd, 2015

    Everyone explained what is MVC... This is outcome of one more design pattern called "separation of concerns", which means a "view" should only handle rendering logic of the model and should not be co...

    Anil Nivargi

    • Jun 26th, 2014

    The MVC consists of three kinds of Objects i.e Model,View and Controller. Lets start explaining one by one. 1) Model- It handles data processing and database works part. Model processes event...


    Mystique Function

    Today we have a special function called Mystique Function.Mystique function for any value x is denoted by H(x). H(x) is defined as the count of positive integers such that (Let k be one of such positive integer)

    1) x%k=0

    2) for every integer z it satisfies (z^k-z)%k=0.

    3) k>1

    Now given a value x you need to print the sum of H(2)+H(3)+H(4)..H(x).


    Query multiples

    You are given an array arr with indices numbered from 1 to N.

    You will be given Q queries of the form i X. This query means, consider all arr[i], arr[i+1], .. arr[N] and, among these numbers, output the number of multiples of X.


    First line consists of two integers; N and Q.

    Next Q lines consist of one query, as described in the problem statement.


    OOPs Interface

    Why interfaces is needed in Java?


    • Dec 2nd, 2015

    Of course that is right answer. Mainly using interface we are achieving abstraction in Java.

    Sreenivasulu Medepalli

    • Dec 2nd, 2015

    If you don't know full implementation of that class at that situation we need to go for interface. In subclass we are implementing that interface and methods.


    Why Hash table doesn't allow null values as well as null keys?

    Vinay Kumar

    • Nov 23rd, 2015

    Hashtable is a legacy class. hash table doesnt allow duplicate object as a key and value beacause hashtable implements hashcode () method. Hash code method compute object hashcode number if object is ...


    Core Java and Java

    What are differences between Core Java and Java?

    Raviteja alluri

    • Oct 19th, 2015

    The difference between Core Java and Java is Core Java : It will covers all basic things like OOPS concepts, Exception Handling, Collections, IoStreams etc Java : It will also covers oops concepts an...

Showing Questions 1 - 20 of 587 Questions
First | Prev | Next | Last Page
Sort by: 
Jump to Page:


Have Interview Question?

Please select the most appropriate category and mention a brief question title along with clear question details.

Ask Question

Login to Ask Question or Register your free account   

Category :
Sub Category :
Question Title:
Question in Detail :
Job Role (Optional) :
Company (Optional) :

Optional Features

Register at GeekInterview

Register me.

Subscribe to GeekInterview Newsletter

Yes, Subscribe me to Interview & Career Tips