Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T; 3. Newthread() { 4. T = New Thread(this,"my Thread"); 5. T.start(); 6. } 7. } 8. Class Multithreaded_programing { 9. Public Static Void Main(string Args[]) { 10. New Newthread(); 11. } 12. }

Answer»

Thread t has been made by using Runnable interface, hence it is necessary to use inherited abstract method RUN() method to specify instructions to be implemented on the thread, since no run() method is used it gives a COMPILATION error.

Output:

$ javac multithreaded_programing.java
The TYPE NEWTHREAD must implement the inherited abstract method Runnable.run()

Thread t has been made by using Runnable interface, hence it is necessary to use inherited abstract method run() method to specify instructions to be implemented on the thread, since no run() method is used it gives a compilation error.

Output:

$ javac multithreaded_programing.java
The type newthread must implement the inherited abstract method Runnable.run()

2.

What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T; 3. Newthread() { 4. T = New Thread(this,"new Thread"); 5. T.start(); 6. } 7. Public Void Run() { 8. T.setpriority(thread.max_priority); 9. System.out.println(t); 10. } 11. } 12. Class Multithreaded_programing { 13. Public Static Void Main(string Args[]) { 14. New Newthread(); 15. } 16. }

Answer»

Thread t has been made with DEFAULT PRIORITY value 5 but in RUN method the priority has been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code ‘t.setPriority(Thread.MAX_PRIORITY);’ using the setPriority function of thread t.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[New Thread,10,main]

Thread t has been made with default priority value 5 but in run method the priority has been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code ‘t.setPriority(Thread.MAX_PRIORITY);’ using the setPriority function of thread t.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[New Thread,10,main]

3.

What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T1,t2; 3. Newthread() { 4. T1 = New Thread(this,"thread_1"); 5. T2 = New Thread(this,"thread_2"); 6. T1.start(); 7. T2.start(); 8. } 9. Public Void Run() { 10. T2.setpriority(thread.max_priority); 11. System.out.print(t1.equals(t2)); 12. } 13. } 14. Class Multithreaded_programing { 15. Public Static Void Main(string Args[]) { 16. New Newthread(); 17. } 18. }

Answer»

Threads t1 & t2 are created by class newthread that is implementing runnable INTERFACE, hence both the threads are provided their own run() METHOD specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence FALSEFALSE is printed.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse

Threads t1 & t2 are created by class newthread that is implementing runnable interface, hence both the threads are provided their own run() method specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence falsefalse is printed.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse

4.

Which Class Is Used To Make A Thread?

Answer»

THREAD class is used to make THREADS in java, Thread encapsulates a thread of execution. To CREATE a new thread the program will EITHER extend Thread or implement the RUNNABLE interface.

Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface.

5.

Which Of Interface Contains All The Methods Used For Handling Thread Related Operations In Java?

Answer»

Runnable INTERFACE DEFINES all the methods for HANDLING thread OPERATIONS in Java.

Runnable interface defines all the methods for handling thread operations in Java.

6.

Will This Program Generate Same Output Is Executed Again? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Int Y = Double Z = Math.random(); 4. System.out.print(y); 5. } 6. }

Answer»

There is no RELATION between random NUMBERS generated PREVIOUSLY in Java.

There is no relation between random numbers generated previously in Java.

7.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 102; 4. Double Y = 5; 5. Double Z = Math.ieeeremainder(x, Y); 6. System.out.print(z);} 7. } 8. }

Answer»

IEEEremainder() returns the REMAINDER of dividend / devisor. Here dividend is 102 and devisor is 5 therefore remainder is 2. It is similar to MODULUS – ‘%’ operator of C/C++ LANGUAGE.

OUTPUT:

$ javac Output.java
$ java Output
2

IEEEremainder() returns the remainder of dividend / devisor. Here dividend is 102 and devisor is 5 therefore remainder is 2. It is similar to modulus – ‘%’ operator of C/C++ language.

Output:

$ javac Output.java
$ java Output
2

8.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y = (int) Math.todegrees(x); 5. System.out.print(y); 6. } 7. }

Answer»

3.14 in degree 179.9087. We usually take it to be 180. Buts here we have TYPE casted it to INTEGER DATA type hence 179.

Output:

$ javac Output.java
$ java Output
179

3.14 in degree 179.9087. We usually take it to be 180. Buts here we have type casted it to integer data type hence 179.

Output:

$ javac Output.java
$ java Output
179

9.

Toradian() And Todegree() Methods Were Added By Which Version Of Java?

Answer»

TORADIAN() and TODEGREE() methods were added by Java 2.0 before that there was no method which COULD directly convert degree into radians and vice VERSA.

toRadian() and toDegree() methods were added by Java 2.0 before that there was no method which could directly convert degree into radians and vice versa.

10.

Which Method Returns The Remainder Of Dividend / Devisor?

Answer»

IEEEremainder() RETURNS the REMAINDER of DIVIDEND / DEVISOR.

IEEEremainder() returns the remainder of dividend / devisor.

11.

Which Class Contains All The Methods Present In Math Class?

Answer»

SystemMath class defines COMPLETE SET of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is GUARANTEED to generate precisely identical RESULTS ACROSS all Java implementations.

SystemMath class defines complete set of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is guaranteed to generate precisely identical results across all Java implementations.

12.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y = (int) Math.floor(x); 5. System.out.print(y); 6. } 7. }

Answer»

double floor(double X) RETURNS a largest WHOLE number less than or equal to variable X. Here the smallest whole number less than 3.14 is 3.

Output:

$ JAVAC Output.JAVA
$ java Output
3

double floor(double X) returns a largest whole number less than or equal to variable X. Here the smallest whole number less than 3.14 is 3.

Output:

$ javac Output.java
$ java Output
3

13.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y = (int) Math.ceil(x); 5. System.out.print(y); 6. } 7. }

Answer»

ciel(DOUBLE X) RETURNS the SMALLEST whole number greater than or equal to variable x.

OUTPUT:

$ javac Output.java
$ java Output
4

ciel(double X) returns the smallest whole number greater than or equal to variable x.

Output:

$ javac Output.java
$ java Output
4

14.

Which Method Return A Largest Whole Number Less Than Or Equal To Variable X?

Answer»

DOUBLE floor(double X) RETURNS a largest whole number LESS than or EQUAL to variable X.

double floor(double X) returns a largest whole number less than or equal to variable X.

15.

Which Method Return A Smallest Whole Number Greater Than Or Equal To Variable X?

Answer»

DOUBLE CIEL(double X) returns the smallest whole NUMBER greater than or equal to variable X.

double ciel(double X) returns the smallest whole number greater than or equal to variable X.

16.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 2.0; 4. Double Y = 3.0; 5. Double Z = Math.pow( X, Y ); 6. System.out.print(z); 7. } 8. }

Answer»

Math.pow(x, y) METHODS returns value of y to the POWER x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.

OUTPUT:

$ JAVAC Output.java
$ java Output
8.0

Math.pow(x, y) methods returns value of y to the power x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.

Output:

$ javac Output.java
$ java Output
8.0

17.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Int X = 3.14; 4. Int Y = (int) Math.abs(x); 5. System.out.print(y); 6. } 7. }

Answer»

OUTPUT:

$ JAVAC Output.JAVA
$ java Output
3

Output:

$ javac Output.java
$ java Output
3

18.

What Is The Output Of This Program? 1. Class A { 2. Int X; 3. Int Y; 4. Void Display() { 5. System.out.print(x + " " + Y); 6. } 7. } 8. Class Output { 9. Public Static Void Main(string Args[]) { 10. A Obj1 = New A(); 11. A Obj2 = New A(); 12. Obj1.x = 1; 13. Obj1.y = 2; 14. Obj2 = Obj1.clone(); 15. Obj1.display(); 16. Obj2.display(); 17. } 18. }

Answer»

clone() method of OBJECT class is USED to GENERATE duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.

OUTPUT:

$ javac Output.java
$ java Output
1 2 1 2

clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.

Output:

$ javac Output.java
$ java Output
1 2 1 2

19.

Which Class Contains Only Floating Point Functions?

Answer»

Math class contains all the FLOATING point functions that are USED for geometry, trigonometry, as well as several general purpose methods. Example : SIN(), COS(), exp(), sqrt() ETC.

Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.

20.

Which Method Is A Rounding Function Of Math Class?

Answer»

MAX(), MIN() and ABS() are all ROUNDING FUNCTIONS.

max(), min() and abs() are all rounding functions.

21.

Which Class Is Superclass Of All Other Classes?

Answer»

The OBJECT CLASS class is SUPERCLASS of all other CLASSES.

The object class class is superclass of all other classes.

22.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4. Byte B[] = { 71, 72, 73, 74, 75, 76 }; 5. System.arraycopy(a, 1, B, 3, 0); 6. System.out.print(new String(a) + " " + New String(b)); 7. } 8. }

Answer»

SINCE last PARAMETER of System.arraycopy(a,1,b,3,0) is 0 NOTHING is COPIED from array a to array b, hence b REMAINS as it is.

Since last parameter of System.arraycopy(a,1,b,3,0) is 0 nothing is copied from array a to array b, hence b remains as it is.

23.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4. Byte B[] = { 71, 72, 73, 74, 75, 76 }; 5. System.arraycopy(a, 2, B, 1, A.length-2); 6. System.out.print(new String(a) + " " + New String(b)); 7. } 8. }

Answer»

OUTPUT:

$ JAVAC Output.JAVA
$ java Output
ABCDEF GCDEFL

Output:

$ javac Output.java
$ java Output
ABCDEF GCDEFL

24.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4. Byte B[] = { 71, 72, 73, 74, 75, 76 }; 5. System.arraycopy(a , 0, B, 0, A.length); 6. System.out.print(new String(a) + " " + New String(b)); 7. } 8. }

Answer»

SYSTEM.arraycopy() is a method of CLASS System which is USED to COPY a string into another string.

Output:

$ javac Output.JAVA
$ java Output
ABCDEF ABCDEF

System.arraycopy() is a method of class System which is used to copy a string into another string.

Output:

$ javac Output.java
$ java Output
ABCDEF ABCDEF

25.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Long Start, End; 4. Start = System.currenttimemillis(); 5. For (int I = 0; I < 10000000; I++); 6. End = System.currenttimemillis(); 7. System.out.print(end - Start); 8. } 9. }

Answer»

END time is the time taken by LOOP to execute it can be any non zero VALUE depending on the System.

OUTPUT:

$ javac Output.java
$ java Output
78

end time is the time taken by loop to execute it can be any non zero value depending on the System.

Output:

$ javac Output.java
$ java Output
78

26.

Standard Output Variable ‘out’ Is Defined In Which Class?

Answer»

Standard OUTPUT variable ‘out’ is DEFINED in SYSTEM CLASS. out is usually used in print statement i:e System.out.print().

Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().

27.

Which Class Have Only One Field ‘type’?

Answer»

The Void class has one field, TYPE, which HOLDS a reference to the Class OBJECT for the type void.

The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

28.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Long I = New Long(256); 4. System.out.print(i.hashcode()); 5. } 6. }

Answer»

OUTPUT:

$ JAVAC Output.JAVA
$ java Output
256

Output:

$ javac Output.java
$ java Output
256

29.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Integer I = New Integer(257); 4. Float X = I.floatvalue(); 5. System.out.print(x); 6. } 7. }

Answer»

OUTPUT:

$ JAVAC Output.JAVA
$ java Output
257.0

Output:

$ javac Output.java
$ java Output
257.0

30.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Integer I = New Integer(257); 4. Byte X = I.bytevalue(); 5. System.out.print(x); 6. } 7. }

Answer»

i.byteValue() METHOD returns the value of wrapper i as a byte value. i is 257, RANGE of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.

Output:

$ JAVAC Output.JAVA
$ java Output
1

i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.

Output:

$ javac Output.java
$ java Output
1

31.

What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Char A[] = {'a', '5', 'a', ' '}; 4. System.out.print(character.isdigit(a[0]) + " "); 5. System.out.print(character.iswhitespace(a[3]) + " "); 6. System.out.print(character.isuppercase(a[2])); 7. } 8. }

Answer»

Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character false is RETURNED. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is an upper CASE letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.

Output:

$ javac Output.JAVA
$ java Output
false true true

Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is an upper case letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.

Output:

$ javac Output.java
$ java Output
false true true

32.

Which Methods Is Used To Obtain Value Of Invoking Object As A Long?

Answer»

LONG longValue() is used to OBTAIN VALUE of INVOKING object as a long.

long longValue() is used to obtain value of invoking object as a long.

33.

What Is A Super Class Of Wrappers Long, Character & Integer?

Answer»

Number is an abstract class CONTAINING subclasses DOUBLE, FLOAT, Byte, SHORT, INTEGER and Long.

Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

34.

What Is The Output Of This Program? 1. Class Binary { 2. Public Static Void Main(string Args[]) { 3. Int Num = 17; 4. System.out.print(integer.tobinarystring(num)); 5. } 6. }

Answer»

OUTPUT:

$ JAVAC binary.JAVA
$ java binary
10001

output:

$ javac binary.java
$ java binary
10001

35.

What Is The Output Of This Program? 1. Class Isnan_output { 2. Public Static Void Main(string Args[]) { 3. Double D = New Double(1 / 0.); 4. Boolean X = D.isnan(); 5. System.out.print(x); 6. } 7. }

Answer»

isisNaN() method returns TRUE is the value being TESTED is a number. 1/0. is infinitely large in magnitude, which cant not be DEFINED as a number hence false is stored in x.

Output:

$ javac isNaN_output.JAVA
$ java isNaN_output
false

isisNaN() method returns true is the value being tested is a number. 1/0. is infinitely large in magnitude, which cant not be defined as a number hence false is stored in x.

Output:

$ javac isNaN_output.java
$ java isNaN_output
false

36.

What Is The Output Of This Program? 1. Class Isinfinite_output { 2. Public Static Void Main(string Args[]) { 3. Double D = New Double(1 / 0.); 4. Boolean X = D.isinfinite(); 5. System.out.print(x); 6. } 7. }

Answer»

isInfinite() METHOD RETURNS true is the VALUE being TESTED is infinitely large or small in magnitude. 1/0. is infinitely large in magnitude hence true is stored in x.

Output:

$ javac isinfinite_output.JAVA
$ java isinfinite_output
true

isInfinite() method returns true is the value being tested is infinitely large or small in magnitude. 1/0. is infinitely large in magnitude hence true is stored in x.

Output:

$ javac isinfinite_output.java
$ java isinfinite_output
true

37.

Which Methods Is Used To Check For Infinitely Large And Small Values?

Answer»

isinfinite() METHOD RETURNS TRUE is the VALUE being tested is infinitely large or small in magnitude.

isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

38.

What Is A Super Class Of Wrappers Double & Integer?

Answer»

Number is an abstract class containing SUBCLASSES DOUBLE, Float, BYTE, SHORT, Integer and Long.

Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

39.

Which Classes Is Not Included In Java.lang?

Answer»

ARRAY CLASS is a MEMBER of java.util.

Array class is a member of java.util.