I have a java file which imports java.sql.Date class. How can I typecast an object of type java.sql.Timestamp to java.sql.Date , in that file ? Both java.sql.Timestamp and java.sql.Date extend from java.util.Date class.
You can't. A typecast of an object reference cannot change the object into a different kind of object.
If you had an object reference that was declared as a java.util.Date, but you knew that it actually referred to one of the subclasses, java.sql.Date or java.sql.Timestamp, you could typecast the object reference to one of those subclasses.
If you have a java.sql.Timestamp and you want to make a java.sql.Date, you need to construct a new java.sql.Timestamp that represents the same time as the java.sql.Date does. You can do that with: -
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.