2
Q:

main() {

int i;

printf("%d",scanf("%d",&i)); // value 10 is given as input here

}

A) 1 B) 2
C) 3 D) 4

Answer:   A) 1



Explanation:

Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.

Subject: Java
Q:

What is the Set interface ?

Answer

- The Set interface provides methods for accessing the elements of a finite mathematical set


- Sets do not allow duplicate elements


- Contains no methods other than those inherited from Collection


- It adds the restriction that duplicate elements are prohibited


- Two Set objects are equal if they contain the same elements

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1750
Q:

How do you decide when to use ArrayList and When to use LinkedList?

Answer

If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList offers the optimal collection. If, however, you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList offers the better implementation.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1855
Q:

How do you decide when to use HashMap and when to use TreeMap ?

Answer

For inserting, deleting, and locating elements in a Map, the HashMap offers the best alternative. If, however, you need to traverse the keys in a sorted order, then TreeMap is your better alternative. Depending upon the size of your collection, it may be faster to add elements to a HashMap, then convert the map to a TreeMap for sorted key traversal.


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 1661
Q:

How do you traverse through a collection using its Iterator?

Answer

To use an iterator to traverse through the contents of a collection, follow these steps:


- Obtain an iterator to the start of the collection by calling the collections iterator() method.


- Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true.


- Within the loop, obtain each element by calling next().

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1777
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 11588
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 1599
Q:

When finally block is executed?

Answer

If exception is generated  in try and if that exception is not catch by any catch then finally is executed.


If exception is generated in try and if that exception is caught by one of catch statements then also finally is executed.


if no exception is generated then also finally is executed.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2448
Q:

Why synchronization?

Answer

When ever two or more threads are sharing same data for updating then unpredicted result will be there in the data.


For Example take a thread is depositing amount in Account Object and another thread is withdrawing amount from the same Account Object.


when ever both threads are executed simultaneously then unexpected result is stored in the balance of the  Account Object. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2068