51-60 Flashcards
Give an example of use of Pointers in Java class.
There are no pointers in Java. So we can’t use concept of pointers in Java.
How can we restrict inheritance for a class so that no class can be inherited from it?
If we want a class not to be extended further by any class, we can use the keyword Final with the class name.
What’s difference between Stack and Queue?
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 can we use primitive data types as objects?
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.
Which types of exceptions are caught at compile time?
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.
Describe different states of a thread.
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.
Can we use a default constructor of a class even if an explicit constructor is defined?
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.
Can we override a method by using same method name and arguments but different return types?
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.