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…

Java-Object Cloning

Object Cloning The clone method generates a duplicate copy of the object on which it is called. Only classes that implement the Cloneable interface can be cloned. The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone) to be made. If … 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-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-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-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…