Java-Object Class

Object Class The Object class is a superclass of all other classes. This means all other classes are subclass of the Object class. The important methods in the Object class are briefly described in the following table. These methods are inherited by every object created in a Java program. Method Purpose Object clone() Creates a … Read more…

Java-getClass

getClass The getClass() method returns the runtime class of an object. The getSuperclass() method returns the Class representing the superclass of the entity represented by this Class. Program Program Source class Data1 { } class Data2 extends Data1 { } class Javaapp { public static void main(String args[]) { Data2 d2 = new Data2(); System.out.println(“Data2 Superclass is : “+d2.getClass().getSuperclass()); … Read more…

Java-Instanceof keyword

Instanceof keyword The instanceof is used to knowing the type of an object during run time. The instanceof operator has this general form : ref instanceof type Here, ‘ref’ is a reference to an instance of a class, and ‘type’ is a class type. If ‘ref’ is of the specified type or can be cast into the specified … Read more…

Java-Object Reference

Object Reference Object is a superclass of all other classes. This means that a reference variable of type Object can refer to an object of any other class. Program Program Source class Data { int data1; } public class Javaapp { public static void main(String[] args) { Data dobj = new Data(); dobj.data1 = 100; … Read more…

Java-Overriding toString Method

Overriding toString Method The toString( ) method returns a string that contains a description of the object on which it is called. If you want to represent any object as a string, toString() method comes into existence. Many classes override this method. This method is automatically called when an object is output using println( ). Program : Without … Read more…

Java-Overriding equals Method

Overriding equals Method The equals( ) method compares two object reference, to see whether they refer to the same object. Program : Without Overriding equals   The following example overrides equals() method . Program : With Overriding equals Program Source : Without Overriding equals class Book { String name; Book(String na) { name = na; } } public class … Read more…