Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

import mypack.*; (asterisk and without asterisk)  RSS feed

Rayudu addagarla
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/* class A*/
package pack1;
public class A{
public void call(){
System.out.println("Hello Darling");
/* class B which uses class A by importing pack1*/
import pack1.*;
public class B{
public static void main(String args[ ]){
A obj =new A();;
/***problem *********************/
i am using jdk1.3
"c:\java" current dir.
when compiled at Dos prompt
c:\java> javac -d . --> creates directory pack1-->puts A.class in that dir.
now when compiling
C:\java> javac

C:\Java> javac cannot resolve symbo
symbol : constructor A ()
location: class A
A obj =new A();
^ cannot resolve symbo
symbol : method call ()
location: class A;
2 errors
but it works fine and compiles and output IF
i keep
import pack1.A in class B instead of import pack1.*;
i have set the classpath to the current directory
c:\java>set classpath=%classpath%;.;
/* dot indicates current dir */
Can anyone help me the problem the asterisk with and without
Mark Ziebell
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry no explanation but an interesting problem.
Perhaps the answer is that it is not good practice to have the in the default package of B when it is not part of the default package.
So the rule is
import pack1.A
does not get confused with in the default package
import pack1.*
recompiles in the default package and puts the class file in the same directory (ie does not use javac -d . when it recompiles A)
Of course using an IDE such as Visual Age for Java prevents you from ever having a java file not in its own package.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!