The Cosmic Superclass Every Java class youve ever written isautomatically a subclass of java.lang.Object. This means thatpublic
Question:
The Cosmic Superclass Every Java class you’ve ever written isautomatically a subclass of java.lang.Object. This means thatpublic methods from Object are inherited by your classes, and youmay override them. Several of these methods have signficantimplications, and we will concern ourselves with 2 of them:toString() and equals(Object other) To start Write a Student classthat has two instance variables: String name and int age. Write amain method that constructs such an object, sets the instancevariables, and then prints out the object. Something like this:Student s = new Student ( " Brian " , 22); System . out . println (" Student : " + s ); What does it print out? toString() WheneverJava needs to treat an object like a String, whether that be toprint out the object, or to use it to build up text (such as in theprevious example), it automatically calls the toString method toget the appropriate value. This works because every object has thismethod! You can override the method to change the Stringrepresentation for your custom objects. 1 Turn in a class thatloads an ArrayList with Student objects and prints out the entirelist: ArrayList < Student > students = new ArrayList