Home arrow static arrow Java Programming [Archive] - 2 Simple Questions
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - 2 Simple Questions
This topic has 1 reply on 1 page.

Posts:164
Registered: 1/23/04
2 Simple Questions  
Jul 3, 2004 12:59 AM



 
The files SomeClass.java and ExtendsTest2.java both exist in the same directory on my machine. I successfully compiled SomeClass.java but I get an error when I compile ExtendsTest2.java (version 1):


ExtendsTest2.java:1: '.' expected
import SomeClass;
1 Error


I have "." in my classpath too so I'm not sure why I'm getting this error.

Question 2 involves ExtendsTest2.java (version 2). The only difference between version 1 and 2 is that version 2 tries to use a class that was imported in SomeClass.java. Again the compiler complains. I guess I'm kinda fuzzy as to why you can't use a class that was imported by the class you're extending.


SomeClass.java

import javax.xml.transform.dom.DOMSource; public class SomeClass {	public static void printIt() {		System.out.println("SomeClass.printIt");	}}


ExtendsTest2.javaVERSION 1
import SomeClass; public class ExtendsTest2 extends SomeClass {	public static void main (String[] args) {		SomeClass someClass = new SomeClass();	} }


ExtendsTest2.javaVERSION 2
import SomeClass; public class ExtendsTest2 extends SomeClass {	public static void main (String[] args) {		SomeClass someClass = new SomeClass();		DomSource domSource = new DomSource(); // Heres the new line	}}
 

Posts:4,130
Registered: 3/31/99
Re: 2 Simple Questions  
Jul 3, 2004 5:10 AM (reply 1 of 1)



 
Java 1.4 does not allow you to import a class from the default (unnamed) package. You do not need to import classes if they are in the same package. Since your classes are in the default package, you do not need to use import.
 
This topic has 1 reply on 1 page.