当前位置: 技术问答>java相关
我是个初学者,请帮帮我
来源: 互联网 发布时间:2017-03-28
本文导语: 在以下的程序中,编译时能通过。运行时出现以下错误。 Exception in thread "main" java.lang.NoClassDefFoundError:InheritAbstract abstract class SuperAbstract{ void a(){ System.out.println("defined a() in SuperAbstrct."); } abstract void b(); abstract...
在以下的程序中,编译时能通过。运行时出现以下错误。
Exception in thread "main" java.lang.NoClassDefFoundError:InheritAbstract
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:InheritAbstract
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b(){
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
}
|
把public void main(String args[])改成public static void main(String args[])
|
我检查过了你的程序有错误:
正确的应该是这样的!
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
//定义一个接口
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b()
{
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public static void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
正确的应该是这样的!
abstract class SuperAbstract{
void a(){
System.out.println("defined a() in SuperAbstrct.");
}
abstract void b();
abstract int c(int i);
}
//定义一个接口
interface AsSuper{
void x();
void y();
}
abstract class SubAbstract extends SuperAbstract implements AsSuper{
public void b()
{
System.out.println("in SubAbstract,implemented b() from SuperAbstract.");
}
}
public class InheritAbstract extends SubAbstract{
public void x(){
System.out.println("in mainclass,must implement x() from interface!");
}
public void y(){
System.out.println("in mainclass ,must implement y() fome interface!");
}
public int c(int i){
System.out.println(i+"in mainclass,implement c() from SuperAbstract.");
return i;
}
public String f(){
return "in mainclass ,implement f() from SubAbstract.";
}
public void g(){
System.out.println("in mainclass,implement g() from SubAbstract.");
}
public static void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
}
|
你的环境变量设置好了吗?
|
public void main(String args[]){
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
最少这里会出错
应该为
public static void main(String args[]){
......
}
static在这儿我记得是必不可少
InheritAbstract instance=new InheritAbstract();
instance.x();
instance.y();
instance.a();
instance.b();
instance.c(100);
System.out.println(instance.f());
instance.g();
}
最少这里会出错
应该为
public static void main(String args[]){
......
}
static在这儿我记得是必不可少
|
检查一下你的环境变量设置吧,这个问题多数是因为环境变量没设好。
注意在最后加上 ;.
注意在最后加上 ;.
|
我试了一下,加上static在void main(....)前面
编译能够能够通过
但是运行的不出结果!
显示:
Exception in thread "main" java.lang.NoSuchMethodError: main
|
注意:public类的名字必须和文件名一致,不然报这个错误
|
你怎么写那么多其次你写的这些应该慢慢来
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。