【发布时间】:2011-03-19 03:00:39
【问题描述】:
我有一个小问题。
二级:
interface jj{
public class ll implements gg{
public static String j ="C:\\";
//some code here
}
}
类ggg:
interface gg{
public class ggg extends JFrame implements jj{
//bunch of code + a textfield
textField = new JTextField();
textField.setBounds(72, 120, 217, 20);
textField.setColumns(10);
//bunch of code
}
}
类aaa
public class aaa implements jj, gg {
public aaa(){
//File chooser here + editing strin "j" from class "ll"
File f = chooser.getSelectedFile();
if(f!=null)
{
jj.ll.j = f.getPath();
//And printing "j" string to the text field from ggg class
gg.ggg.textField.setText(jj.ll.j);
}
}
}
我的问题是,文本字段打印不起作用。我尝试 System.out.println jj.ll.j 字符串来测试它是否有东西。是的,它具有并且按预期工作。
【问题讨论】:
-
你确定你需要接口中的类吗?
-
我的建议是不要在接口中嵌入非接口类。
-
我需要在其他 3 个类中使用 j 字符串。如果java做一个多继承特性会容易得多,但我们有我们所拥有的。
-
@shevchuk,仅当类之间存在具有父子关系的对象图时才使用继承。您不需要继承即可从其他 3 个类访问相同的对象。
-
这是故意混淆的吗?这是我见过的最奇怪的声明“公共常量”的方式之一。
标签: java inheritance interface implementation