Sie sind auf Seite 1von 64

Miscellaneous Interview Questions

For CSE and IT

Interview Questions
What is synchronization and why is it important?

Answer
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is not possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value

Question
Does garbage collection guarantee that a program will not run out of memory?

Answer
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

Question
What value does readLine() return when it has reached the end of a file?

Answer
The readLine() method returns null when it has reached the end of a file.

Question
To what value is a variable of the String type automatically initialized?

Answer
The default value of an String type is null.

Question
What class is the top of the AWT event hierarchy?

Answer
The java.awt.AWTEvent class is the highestlevel class in the AWT event-class hierarchy.

Question
When a thread is created and started, what is its initial state?

Answer
A thread is in the ready state after it has been created and started.

Question
What is the range of the short type?

Answer
The range of the short type is -(2^15) to 2^15 - 1.

Question
What is the range of the char type?

Answer
The range of the char type is 0 to 2^16 - 1.

Question
What is the purpose of finalization?

Answer
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

Question
What is the difference between the Boolean & operator and the && operator?

Answer
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

Question
What is the purpose of the Runtime class?

Answer
The purpose of the Runtime class is to provide access to the Java runtime environment

Question
How many times may an object's finalize() method be invoked by the garbage collector?

Answer
An object's finalize() method may only be invoked once by the garbage collector.

Question
What is the argument type of a Java program's main() method?

Answer
A program's main() method takes an argument of the String[] type.

Question
What must a class do to implement an interface?

Answer
It must provide all of the methods in the interface and identify the interface in its implements clause.

Question
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

Answer
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Question
If a class is declared without any access modifiers, where may the class be accessed?

Answer
A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Question
Name the eight primitive Java types.

Answer
The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Question
What is the difference between the paint() and repaint() methods?

Answer
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Question
If a method is declared as protected, where may the method be accessed?

Answer
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Question
What is Reference Variable?

Answer
Reference variable provides an alternative name for previously defined variable. Data_type & reference_name = variable_name

Question
What are the advantages of new operator over malloc()?

Answer
It automatically computes the size of the data object. So we dont need the sizeof operator. It automatically returns the correct pointer type. So we dont need to use type casting It is possible to initialize the object while creating the memory space. Like any other operator new can be overloaded

Question
What is endl and setw?

Answer
endl: it is a manipulator, when used in the output statement, causes a linefeed to be inserted. setw: it is also a manipulator to make the output right justified.

Question
What is inline function?

Answer
When we call a function then control jumps to the function and come back to the calling function after execution. It take lots of time. In c++, using inline function if we call an inline function the compiler replaces the function call with the corresponding function code but control not jump to function.

Question
What happens if we add the static keyword before a method?

Answer
A static method can have access to only other static members. A static member function can be called using the class name.

Question
What are the characteristics of a constructor?

Answer
The name of the constructor must be same as the class name The constructor is declared with no return type not even void Constructor may not be static It cant be inherited

Question
What is the difference between class and structure?

Answer
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private.

Question
What is friend function?

Answer
As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition. A non membered function which declared in class defination through which we can access the private and protected data members of a class is called a friend function.

Question
What is virtual base class?

Answer
When we declare a class as virtual, then only one copy of that class can be inherited, regardless of how many objects are sharing the base class.

Question
What is virtual function?

Question
What is seekg(), seekp(), tellg(), and tellp()?

Answer
seekg(): moves the file pointer (input) to a specified location seekp(): moves the file pointer (output) to a specified location tellg(): gives the current position of the get pointer tellp(): gives the current position of the put pointer.

Question
How many operator do we have in C?

Answer
Arithmetic Relational Logical Increment and decrement Assignment Conditional Bitwise

Question
What are the string handling functions present in C?

Answer
strlen() strcpy() strcat() strcmp()

Das könnte Ihnen auch gefallen