主類怎么加進去啊,代碼錯了不會改
public class dog { int age =5; String name="樂樂"; String color="白色"; int weight =10; String sex="female"; void eat() { } void look() { } void yao() { } void run() { } void swim() { } {System.out.println("beef"); System.out.println("person"); System.out.println("旺旺~~~~~"); System.out.println("quick"); System.out.println("會"); } public class dog1 extends dog {public dog1(){ super(); }??? public class dog2 extends dog??? {public dog2(){??? this();??? ??? }??? }
??? public static void main (String args[]) { dog dog=new dog(); System.out.println("姓名:"+dog.name); System.out.println("年齡:"+dog.age); System.out.println("顏色:"+dog.color); System.out.println("體重:"+dog.weight); System.out.println("性別:"+dog.sex); dog.eat(); dog.look(); dog.yao(); dog.run(); dog.swim();}
2016-10-09
public?class?Dog?{ int?age?=5; String?name="樂樂"; String?color="白色"; int?weight?=10; String?sex="female"; void?eat() { } void?look() { } void?yao() { } void?run() { } void?swim() { } { System.out.println("beef"); System.out.println("person"); System.out.println("旺旺~~~~~"); System.out.println("quick"); System.out.println("會"); } ????class?dog1?extends?Dog{public?dog1(){ super();??}?}???? ????class?dog2?extends?Dog{public?dog2(){???super();??}?}? ????public?static?void?main(String?args[]){ Dog?dog=new?Dog(); System.out.println("姓名:"+dog.name); System.out.println("年齡:"+dog.age); System.out.println("顏色:"+dog.color); System.out.println("體重:"+dog.weight); System.out.println("性別:"+dog.sex); dog.eat(); dog.look(); dog.yao(); dog.run(); dog.swim(); ????} }2017-02-17
public class Test {
int age =5;
String name="樂樂";
String color="白色";
int weight =10;
String sex="female";
void eat() {
System.out.println("beef");
}
void look() {
System.out.println("person");
}
void yao() {
System.out.println("旺旺~~~~~");
}
void run() {
System.out.println("quick");
}
void swim() {
System.out.println("會");
}
public class dog1 extends Test {
public dog1(){ super(); ?
}
}
public class dog2 extends Test ? ?{
public dog2(){
super(); ? ? ??
} ? ?
}?
public static void main (String args[]) {
Test dog=new Test();
System.out.println("姓名:"+dog.name);
System.out.println("年齡:"+dog.age);
System.out.println("顏色:"+dog.color);
System.out.println("體重:"+dog.weight);
System.out.println("性別:"+dog.sex);
dog.eat(); ?
dog.look(); ?
dog.yao(); ?
dog.run(); ?
dog.swim();
}
}
2016-10-09
不要在同一個java文件里寫好幾個類,public class一個類中只能出現一次。還有你括號丟了很多啊。主類就是main方法所在的類。你最后丟了個括號,只剩下方法,當然沒類了。
2016-10-09
同一個文件里,只能有一個類為public,另定義的另兩個子類,不能加public。
public class Dog {
?? ?public static void main(String args[]) {
?? ??? ?Dog dog = new Dog();
?? ??? ?System.out.println("姓名:" + dog.name);
?? ??? ?System.out.println("年齡:" + dog.age);
?? ??? ?System.out.println("顏色:" + dog.color);
?? ??? ?System.out.println("體重:" + dog.weight);
?? ??? ?System.out.println("性別:" + dog.sex);
?? ??? ?dog.eat();
?? ??? ?dog.look();
?? ??? ?dog.yao();
?? ??? ?dog.run();
?? ??? ?dog.swim();
?? ?}
?? ?int age = 5;
?? ?String name = "樂樂";
?? ?String color = "白色";
?? ?int weight = 10;
?? ?String sex = "female";
?? ?void eat() {
?? ?}
?? ?void look() {
?? ?}
?? ?void yao() {
?? ?}
?? ?void run() {
?? ?}
?? ?void swim() {
?? ?}
?? ?{
?? ??? ?System.out.println("beef");
?? ??? ?System.out.println("person");
?? ??? ?System.out.println("旺旺~~~~~");
?? ??? ?System.out.println("quick");
?? ??? ?System.out.println("會");
?? ?}
?? ?class dog1 extends Dog {
?? ??? ?public dog1() {
?? ??? ??? ?super();
?? ??? ?}
?? ??? ?class dog2 extends Dog {
?? ??? ??? ?public dog2() {
?? ??? ??? ??? ?super();
?? ??? ??? ?}
?? ??? ?}
?? ?}
}
2016-10-09
dog2 繼承還是用super()啊,你怎么用的this