51-60 Flashcards

1
Q

Give an example of use of Pointers in Java class.

A

There are no pointers in Java. So we can’t use concept of pointers in Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can we restrict inheritance for a class so that no class can be inherited from it?

A

If we want a class not to be extended further by any class, we can use the keyword Final with the class name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s difference between Stack and Queue?

A

Stack and Queue both are used as placeholder for a collection of data. The primary difference between a stack and a queue is that stack is based on Last in First out (LIFO) principle while a queue is based on FIFO (First In First Out) principle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we use primitive data types as objects?

A

Primitive data types like int can be handled as objects by the use of their respective wrapper classes. For example, Integer is a wrapper class for primitive data type int. We can apply different methods to a wrapper class, just like any other object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which types of exceptions are caught at compile time?

A

Checked exceptions can be caught at the time of program compilation. Checked exceptions must be handled by using try catch block in the code in order to successfully compile the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe different states of a thread.

A

Ready: When a thread is created, it’s in Ready state.
Running: A thread currently being executed is in running state.
Waiting: A thread waiting for another thread to free certain resources is in waiting state.
Dead: A thread which has gone dead after execution is in dead state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can we use a default constructor of a class even if an explicit constructor is defined?

A

Java provides a default no argument constructor if no explicit constructor is defined in a Java class. But if an explicit constructor has been defined, default constructor can’t be invoked and developer can use only those constructors which are defined in the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can we override a method by using same method name and arguments but different return types?

A

The basic condition of method overriding is that method name, arguments as well as return type must be exactly same as is that of the method being overridden. Hence using a different return type doesn’t override a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly