Advanced Java interview questions

Q:In Java, what is the difference between an Interface and an Abstract class?

A: An Abstract class declares have at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior.

Q: Can you have virtual functions in Java? Yes or No. If yes, then what are virtual functions?

A: Yes, Java class functions are virtual by default. Virtual functions are functions of subclasses that can be invoked from a reference to their superclass. In other words, the functions of the actual object are called when a function is invoked on the reference to that object.

Q:Write a function to reverse a linked list p in C++?

A:

Link* reverse_list(Link* p)
{
if (p == NULL)
return NULL;

Link* h = p;
p = p->next;
h->next = NULL;
while (p != null)
{
Link* t = p->next;
p->next = h;
h = p;
p = t;
}

return h;
}

Q:In C++, what is the usefulness of Virtual destructors?

A:Virtual destructors are neccessary to reclaim memory that were allocated for objects in the class hierarchy. If a pointer to a base class object is deleted, then the compiler guarantees the various subclass destructors are called in reverse order of the object construction chain.

Q:What are mutex and semaphore? What is the difference between them?

A:A mutex is a synchronization object that allows only one process or thread to access a critical code block. A semaphore on the other hand allows one or more processes or threads to access a critial code block. A semaphore is a multiple mutex.

This entry was posted in Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

8 Comments on Advanced Java interview questions

  1. Brad
    Posted 12/16/2003 at 9:37 am | Permalink

    Question 3 is valid for c/c++ only. It doesn’t apply to Java.

  2. Posted 12/16/2003 at 10:11 am | Permalink

    Thanks, fixed.

  3. Anonymous
    Posted 2/1/2004 at 9:48 pm | Permalink

    I don’t think so. Q #3 and 4 are still C++, not Java.

  4. Posted 5/6/2004 at 6:43 am | Permalink

    Title here is ‘Advanced Java interview questions’ but nothing is advance in these questions. What I request you all to post some good questions in advance java that will help all of us.

  5. suresh Nallamilli
    Posted 7/7/2005 at 4:44 am | Permalink

    Question: Can you get back an object when it is in its finalize method ?

  6. Dalamar
    Posted 11/15/2006 at 5:50 am | Permalink

    An abstract class must have at least 1 abstract method? sure?

  7. madhu
    Posted 8/20/2008 at 12:56 am | Permalink

    yes that is not required to declare abstract method in the abstract class. why because in abstract class we normal method and abstract method, then that is optional . this is my answer what about u send it replay please

  8. david
    Posted 10/28/2008 at 9:48 am | Permalink

    got this on an on-campus interview: tell me the difference between the keywords ‘final’, ‘finally’, and ‘finalize’.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*