Java Questions

Q:

What is the difference between an Interface and an Abstract class?

Answer

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 and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1653
Q:

What is the use of tostring() method?

Answer

If we print any object by using println() or print() methods.


The println() or print() methods internally calls tostring() method and prints the return value of toString() method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1653
Q:

what is non-static member class?

Answer

Non-static member class is a class defined inside outer class with out static modifier.


EX:


class A { // top level class or outer class


    ......


    class B { //non-static member class


    }


    .....


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1643
Q:

What is the Dictionary class?

Answer

- The Dictionary class is an abstract class.


- Classes like Hashtable which map keys to values inherit from this class. 


- An object can be looked for if a dictionary and a key is provided.


- Any non-null object can be used as a key and as a value.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 1629
Q:

What is the syntax to create the object?

Answer

new ClassName();


This expression creates object in heap area and returns that obj address. Here JVM creates object but JVM does not returns object original address. JVM returns duplicate address, duplicate address is also called as hashcode. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1629
Q:

What is JDBC Driver ?

Answer

The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. This driver is used to connect to the database.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1628
Q:

What is the difference between method overriding and overloading?

Answer

Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1624
Q:

When should I use abstract classes and when should I use interfaces?

Answer

Use Interfaces when…


- You see that something in your design will change frequently.


- If various implementations only share method signatures then it is better to use Interfaces.


- You need some classes to use some methods which you don't want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface.


 


Use Abstract Class when…


- If various implementations are of the same kind and use common behavior or status then abstract class is better to use.


- When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.


- Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1623