0
Q:

public abstract class Shape {

private int x;

private int y;

public abstract void draw();

public void setAnchor(int x, int y) {

this.x = x;

this.y = y;

}

}

Which two classes use the Shape class correctly?

A) public class Circle implements Shape { private int radius; B) public abstract class Circle extends Shape { private int radius; }
C) public class Circle extends Shape { private int radius; public void draw(); D) None

Answer:   B) public abstract class Circle extends Shape { private int radius; }



Explanation:

Only B is true

Subject: Java
Q:

Which of these class have only one field 'TYPE' ?

A) Run time B) Process
C) Void D) System
 
Answer & Explanation Answer: C) Void

Explanation:

The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Analyst , IT Trainer

6 5805
Q:

 What is the string contained in s after following lines of code?

StringBuffer s = new StringBuffer(“Hello”); s.deleteCharAt(0);  ?

A) llo B) Hllo
C) ello D) H
 
Answer & Explanation Answer: C) ello

Explanation:

deleteCharAt() method deletes the character at the specified index location and returns the resulting StringBuffer object.

So after deleting the character at 0 ie 'H', the string returns 'ello' as the output.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Analyst , IT Trainer

3 18525
Q:

Which of the following are incorrect form of StringBuffer class constructor  ?

A) StringBuffer(int size , String str) B) StringBuffer(int size)
C) StringBuffer(String str) D) StringBuffer()
 
Answer & Explanation Answer: A) StringBuffer(int size , String str)

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Database Administration , IT Trainer

3 6084
Q:

Does not overriding hashcode() method has any performance implication ?

Answer

A poor Hashcode() function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst , IT Trainer

2 4366
Q:

How do you handle error condition while writing stored procedure or accessing stored procedure from java ?

Answer

Stored procedure should return error code if some operation fails but if stored procedure itself fail than catching SQLException is only choice.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3961
Q:

What is the difference between creating String as new() and literal ?

Answer

When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap.



String s = new String("Test");

does not put the object in String pool , we need to call String.intern() method which is used to put them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.

Report Error

View answer Workspace Report Error Discuss

1 2125
Q:

What is immutable object? Can you write immutable object ?

Answer

Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example is String is immutable in Java. Mostly Immutable are also final in Java, in order to prevent sub class from overriding methods in Java which can compromise Immutability. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

Report Error

View answer Workspace Report Error Discuss

3 2818
Q:

Which two method you need to implement for key Object in HashMap ?

Answer

In order to use any object as Key in HashMap, it must implements equals and hashcode method in Java.

Report Error

View answer Workspace Report Error Discuss

4 5936