Tag Archives: Java-Output

Output of Java programs | Set 9 (Garbage Collection)

Difficulty level : Intermediate In Java, object destruction is taken care by the Garbage Collector module and the objects which do not have any references to them are eligible for garbage collection. Below are some important output questions on Garbage collection. Predict the output of following Java Programs: Program 1 : Output: end of main… Read More »

Output of Java Program | Set 9

Difficulty level : Intermediate Predict the output of following Java Programs. Program 1: Output: Geeksforgeeks Geeksforgeeks Explanation: We know that static variables are called when a class loads and static variables are called only once. Now line 13 results to creation of object which inturn calls the constructor and “Geeksforgeeks” is printed second time. If… Read More »

Output of Java Program | Set 8

Difficulty level : Intermediate Predict the output of following Java Programs. Program 1: Output: Not equal Explanation: Since, s1 and s2 are two different objects the references are not the same, and the == operator compares object reference. So it prints “Not equal”, to compare the actual characters in the string .equals() method must be… Read More »

Output of Java Program | Set 7

Difficulty level : Intermediate Predict the output of following Java Programs. Program 1 : Options : A) 20 B) 100 C) 1000 D) 2 Answer : A) 20 Explanation : Here the class instance variable name(num) is same as calc() method local variable name(num). So for referencing class instance variable from calc() method, this keyword… Read More »

Output of Java Program | Set 6

Difficulty level : Intermediate Predict the output of following Java Programs. Program 1: Output: a b c Explanation: While creating a new object of ‘Third’ type, before calling the default constructor of Third class, the default constructor of super class is called i.e, Second class and then again before the default constructor of super class,… Read More »

Output of Java program | Set 5

Predict the output of following Java Programs. Program 1: Output: String Explanation : In case of method overloading, the most specific method is chosen at compile time. As ‘java.lang.String’ is a more specific type than ‘java.lang.Object’. In this case the method which takes ‘String’ as a parameter is choosen. Program 2: Output: Compile Error at… Read More »