Java Questions

Q:

X implements Y, Z

Arguments:

1. X should be class
2. Y, Z should be interfaces

A) Only 1 is true B) Only 2 is true
C) Both 1 and 2 are true D) None
 
Answer & Explanation Answer: C) Both 1 and 2 are true

Explanation:

Both the statements are true 

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

0 12572
Q:

What will be the output of the following code snippet?

Object s1 = new String("Hello");
Object s2 = new String("Hello");
 
if(s1 == s2) {
  System.out.println("s1 and s2 are ==");
}else if (s1.equals(s2)) {
  System.out.println("s1 and s2 are equals()");
}

Answer

Answer : s1 and s2 are equals()


 


Explanation :



 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

6 12413
Q:

Which of the following statements are equal for a variable declared in the interface ?

1. int X=10
2. public int X=10
3. public static final int X=10

A) Only 1 and 2 are equal B) Only 2 and 3 are equal
C) All are unequal D) All are equal
 
Answer & Explanation Answer: D) All are equal

Explanation:

All the statements are equal because inside an interface a variable declared will be public static final by default 

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

0 12195
Q:

A lock can be acquired on a class.

The above statement is

A) True B) False
C) Both A and B D) None
 
Answer & Explanation Answer: A) True

Explanation:

A lock can be acquired on a class. This lock is acquired on the class's Class object.

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 11727
Q:

How are this() and super() used with constructors?

Answer

Constructors use this to refer to another constructor in the same class with a different parameter list.


Constructors use super to invoke the superclass's constructor. If a constructor uses super, it must use it in the first line; otherwise, the compiler will complain.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 11246
Q:

Can you give few examples of final classes defined in Java API?

Answer

java.lang.String,  java.lang.Math are final classes.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

6 8001
Q:

If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

Answer

The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 7769
Q:

Should a main() method be compulsorily declared in all java classes?

Answer No not required. main() method should be defined only if the source class is a java application.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

10 7730