What will happen when the following code is compiled and executed?

00: package test;
01: public class Test {
02:     public static void main(String [] args) {
03:          Test test = new Test();
04:          System.out.println(test.toString());
05:     }
06: }
Explanation
All objects in Java are inherited from the Object class. Since a Test class does not override a toString() method, it will use its Object class implementation, which returns a string representation of the object as follows: class name (with a full package name) + @ symbol + hexadecimal unsigned value of object's hash code

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes