File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package" Watch "Package" New topic


rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.println("x = " + x);
5. }
6. }
Compilation fails because of an error in line 2 of class Test2.
Compilation fails because of an error in line 4 of class Test2.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

Did you try it out? What do you think yourself? What's exactly your question about this?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
If we excute both package,the program will get complier time exception.
I think the compiler exception will come to line4 from the package2.
Is it correct.
But they told the compiler exception come to line2 from the package2
I hope that you'll get my question
P Ventura
Ranch Hand

Joined: Jan 24, 2007
Posts: 42
Please, don't use the term exception for compilation fail.

I tried to compile the example and the result was a compilation fail at line 4
as I supposed (variable is not visible).

Objective: SCJP 1.5<br /><a href="" target="_blank" rel="nofollow">API</a><br /> <blockquote><font size="1" face="Verdana, Arial">code:</font><hr><pre><font size="2"><br />Double n1 = Double.NaN; Double n2 = Double.NaN;<br /> n1.equals(n2) // true even though Double.NaN != Double.NaN<br />-0.0 == +0.0; // true<br />Double n1 = -0.0;Double n2 = +0.0;<br />n1.equals(n2) // false even though -0.0 == +0.0<br /></font></pre><hr></blockquote>
I agree. Here's the link:
subject: Package
It's not a secret anymore!