Rahul Phadnis

Greenhorn
+ Follow
since Aug 13, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rahul Phadnis

Can some body give me the link to this article. The link on the main page is incorrect. It points to
http://www.javaranch.com/journal/200607/AntPart2.html
18 years ago
Making some changes to the code we can compile it

This also will help to clarify the concepts that previous posters have enlisted.

For me using JDK 1.4, the above code compiles and executes without any modifications.
I think this will explain this a bit more
1. base is variable that points to a array of Base objects.
2. obj = base now make obj point to this array of Base objects.
So we cannot cast obj to an array of Sub. The array members may be of type Sub but the array is of type Base
Look at the following code it explains thing a bit more

[ August 23, 2002: Message edited by: Rahul Phadnis ]
Try this to make it absolutely clear
With JDK 1.4 beta I get the exception
The jdk version info is
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
I am running it on Windows 2000 machine
The exception is
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:129)
at java.io.PrintStream.write(PrintStream.java:306)
at java.io.PrintStream.print(PrintStream.java:465)
at java.io.PrintStream.println(PrintStream.java:602)
at com.rahul.certify.java.TestToString.main(TestToString.java:27)
Exception in thread "main"
The code I used to test is
I think the confusion is due to the way if is written.
take a look at this modified code
import java.io.*;
public class T010
{
public static void main(String args[])
{
System.out.println( method(0) );
}
static int method(int i)
{
try {
if(i < 0) {
throw new IOException();
}

return 0;

}
catch (IOException e) {
return 1;
}
}
If the argument value is not less than 0, 0 will be returned