Java Questions

Q:

When do you use :: Operator in C++?

Answer

:: is the scope resolution operator. When local variable and global variable are having same name, local variable gets the priority. C++ allows flexibility of accessing both the variables through a scope resolution operator

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1389
Q:

How to assign address to the reference?

Answer

ClassName refName = new ClassName();


or


ClassName refName;


refName = new ClassName();

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1388
Q:

How to call a constructor in java?

Answer

Constructor chaining is the process of calling one constructor from another constructor with respect to current object.





Within same class: It can be done using this() keyword for constructors in same class


From base class: by using super() keyword to call constructor from the base class.

Report Error

View answer Workspace Report Error Discuss

1 1378
Q:

What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?

Answer

When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method. But if we are implementing Runnable , it is mandatory to override the run method. The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1375
Q:

What is stored in the 'this' reference?

Answer

This is a keyword and used as reference to Current object address in java. 


It means by using which object the method is called that object hashcode is stored inside the 'this'.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst

0 1361
Q:

Just by seeing the signature of the bean how can you specity whether it is a Statefull of Stateless Session Bean?

Answer

The create method in a stateless bean cannot have arguments, and can only have a single method called create(). While create in Stateful bean can have arguments and could be any method starting with create string eg. create(arg1, arg2, ...). Although it is not compiler checked but in stateless bean the ejb Passivate() and ejb Active() methods has to be empty as these functions are never called by EJB container. As conceptually in stateful session bean we might need to store the clients information hence arguments in createare necessary. While in stateless bean we don't hence no arguments are necessary. It's intutive isn't intutive isn't. I my life I haven't seen such a futuristic server programming tool as EJB.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 1357
Q:

What is the impact of declaring a method as final?

Answer

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1344
Q:

In a class if private data member is declared then how to get value of that data member?

Answer

By using method.


The method used to get the data is called getter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1331