Author:
Daisy Williams
Nov
3
A ClassCastException is thrown when an attempt is made to cast an object, which is not of the appropriate run-time type. It extends from the RuntimeException class. It For example:
Object obj = new Vector();
String s = (String) obj;
Following are the two kinds of constructors for ClassCastException:
ClassCastException()
It will construct a ClassCastException without any detailed message.
ClassCastException(String str)
It will construct a ClassCastException with the specified detailed message.
Permanent link to this post (72 words, estimated 17 secs reading time)
Author:
Daisy Williams
Nov
2
A constructor provides a convenient way to initialize a newly created object at the time of its creation. A constructor is automatically called emmediately after the creation of a new object, but before the new operator completes. All Java classes must have at least one constructor, either explicitly declared in the class or an implicit default constructor. They are typically used to create an object that is an instance of a class. It is written by using the following general syntax:
[access modifier] class name([formal parameter list]) [throws clause] {
// Body of the constructor
}