关于同一个包中的引用问题! 同一个包里面可以 import Comment;也可以不写,直接用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不要写引用语句,然后只要保证这两个文件编译称的class文件在CLASSPATH设置的路径之内,这样就确保它们互相能够找到并且加载。 楼主的意思是不是class Comment{.............}class Reserved{ private Comment comment; ......}comment = new Comment();或者类似Constructor的就可以了,private Comment comment的意思是在Reserved里comment是private的,而不是Comment是private的。Comment的访问控制是在Comment里定义的。 用classpath个人感觉不太好再说我也不知道楼主在说啥 package ch12; import java.lang.* ; import java.sql.* ; import java.util.* ; import javax.servlet.* ; public class ConnPool{ private static final int defaultMaxConnections=3 ; private Vector freeConnections ; private Hashtable boundConnections ; private String driverName ; private String jdbcURL ; private String username ; private String password ; private int maxConnections ; // ------------------------------------ Constructot ------------------------------------- public ConnPool( int numConnections ) { maxConnections=numConnections ; boundConnections=null ; freeConnections=null ; driverName="" ; jdbcURL="" ; username="" ; password="" ; }// -------------------------------------------------------------------------------------- public ConnPool() { this( defaultMaxConnections ) ; } } package ch12; import java.lang.* ; import java.sql.* ; import javax.servlet.*; public class SQLProxy{ ******** private ConnPool connPool ; private Connection conn ; private ResultSet rs ; private ResultSetMetaData rsmd ; private Statement stmt ; private String driverName ; private String jdbcURL ; private String username ; private String password ;// -------------------------------------- Constructor -------------------------------------- public SQLProxy() { connPool=null ; conn=null ; rs=null ; rsmd=null ; stmt=null ; }} 不管怎么样?还是谢谢大家!我的导师让我写一个扩展的来融合这2个问题,我还是不明白,按理说你们说的应该没问题。或许是我的编译什么出了问题。 package ch12; import java.lang.* ; import java.sql.* ; import java.util.* ; import javax.servlet.* ; public class Comment{ private static final int defaultMaxConnections=3 ; private Vector freeConnections ; private Hashtable boundConnections ; private String driverName ; private String jdbcURL ; private String username ; private String password ; private int maxConnections ; // ------------------------------------ Constructot ------------------------------------- public Comment( int numConnections ) { maxConnections=numConnections ; boundConnections=null ; freeConnections=null ; driverName="" ; jdbcURL="" ; username="" ; password="" ; }// -------------------------------------------------------------------------------------- public Comment() { this( defaultMaxConnections ) ; } } package ch12; import java.lang.* ; import java.sql.* ; import javax.servlet.*; public class Reserved{ ******** private Comment comment ; private Connection conn ; private ResultSet rs ; private ResultSetMetaData rsmd ; private Statement stmt ; private String driverName ; private String jdbcURL ; private String username ; private String password ;// -------------------------------------- Constructor -------------------------------------- public Reserved() { comment=null ; conn=null ; rs=null ; rsmd=null ; stmt=null ; }} 不管怎么样?还是谢谢大家!我的导师让我写一个扩展的来融合这2个问题,我还是不明白,按理说你们说的应该没问题。或许是我的编译什么出了问题。 直接用的时候private Comment comment出现错误,在plusedit里也没有显示已经定义过的颜色,别的是有颜色的。 如何通过一个字符串的值得到对应的类型 java如何打开"d:\\Äßあア ﺥﺽ ﺥÃóèД©®"文件夹?多谢! 鼠标放在控件上的时候冒泡显示提示文字,鼠标离开才会消失?怎么做? [技术甄别]用JAVA编写一实用程序——汉字区位码转换 安装jbuilder2005的问题 关于RDF格式文件用jena导出导入问题 请教new Object[] {value} 中这{}什么意思???? 请问如何设置component的焦点 请问 如何在面板(JPanel)上实现一个确定按钮,一按按钮,我的程序就会执行?谢谢 在线等 关闭一个JInternalFrame会产生什么效果? 这个是什么意思?
然后只要保证这两个文件编译称的class文件在CLASSPATH设置的路径之内,
这样就确保它们互相能够找到并且加载。
class Comment{
.............
}class Reserved{
private Comment comment;
......
}comment = new Comment();或者类似Constructor的就可以了,
private Comment comment的意思是在Reserved里comment是private的,而不是Comment是private的。Comment的访问控制是在Comment里定义的。
个人感觉不太好
再说我也不知道楼主在说啥
import java.lang.* ;
import java.sql.* ;
import java.util.* ;
import javax.servlet.* ; public class ConnPool{
private static final int defaultMaxConnections=3 ; private Vector freeConnections ;
private Hashtable boundConnections ;
private String driverName ;
private String jdbcURL ;
private String username ;
private String password ;
private int maxConnections ;
// ------------------------------------ Constructot -------------------------------------
public ConnPool( int numConnections ) {
maxConnections=numConnections ;
boundConnections=null ;
freeConnections=null ;
driverName="" ;
jdbcURL="" ;
username="" ;
password="" ;
}// --------------------------------------------------------------------------------------
public ConnPool() {
this( defaultMaxConnections ) ;
} }
package ch12; import java.lang.* ;
import java.sql.* ;
import javax.servlet.*;
public class SQLProxy{
******** private ConnPool connPool ;
private Connection conn ;
private ResultSet rs ;
private ResultSetMetaData rsmd ;
private Statement stmt ;
private String driverName ;
private String jdbcURL ;
private String username ;
private String password ;// -------------------------------------- Constructor --------------------------------------
public SQLProxy() {
connPool=null ;
conn=null ;
rs=null ;
rsmd=null ;
stmt=null ;
}} 不管怎么样?还是谢谢大家!我的导师让我写一个扩展的来融合这2个问题,我还是不明白,按理说你们说的应该没问题。或许是我的编译什么出了问题。
import java.lang.* ;
import java.sql.* ;
import java.util.* ;
import javax.servlet.* ; public class Comment{
private static final int defaultMaxConnections=3 ; private Vector freeConnections ;
private Hashtable boundConnections ;
private String driverName ;
private String jdbcURL ;
private String username ;
private String password ;
private int maxConnections ;
// ------------------------------------ Constructot -------------------------------------
public Comment( int numConnections ) {
maxConnections=numConnections ;
boundConnections=null ;
freeConnections=null ;
driverName="" ;
jdbcURL="" ;
username="" ;
password="" ;
}// --------------------------------------------------------------------------------------
public Comment() {
this( defaultMaxConnections ) ;
} }
package ch12; import java.lang.* ;
import java.sql.* ;
import javax.servlet.*;
public class Reserved{
******** private Comment comment ;
private Connection conn ;
private ResultSet rs ;
private ResultSetMetaData rsmd ;
private Statement stmt ;
private String driverName ;
private String jdbcURL ;
private String username ;
private String password ;// -------------------------------------- Constructor --------------------------------------
public Reserved() {
comment=null ;
conn=null ;
rs=null ;
rsmd=null ;
stmt=null ;
}} 不管怎么样?还是谢谢大家!我的导师让我写一个扩展的来融合这2个问题,我还是不明白,按理说你们说的应该没问题。或许是我的编译什么出了问题。