測(cè)試類應(yīng)該怎么加?。??
-
/*要求新建一個(gè)PersonTest測(cè)試類,對(duì)person類進(jìn)行測(cè)試*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args... /*要求新建一個(gè)PersonTest測(cè)試類,對(duì)person類進(jìn)行測(cè)試*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args) { // TODO Auto-generated method stub Person p1=new Person();//聲明并實(shí)例化Person類對(duì)象p1 Person p2=new Person();//聲明并實(shí)例化Person類對(duì)象p2 //給p1賦值 p1.name="張三"; p1.age=25; p1.address ="濟(jì)南"; p1.sex ='m'; p1.weight =100; //給p2賦值 p2.name ="李四"; p2.age =30; p2.address ="北京"; p2.sex ='w'; p2.weight =80; System.out.println("名字:"+p1.name +" ,年齡:"+p1.age +" ,家庭住址:"+p1.address +" ,性別:"+p1.sex +" ,體重:"+p1.weight ); System.out.println("名字:"+p2.name +" ,年齡:"+p2.age +" ,家庭住址:"+p2.address +" ,性別:"+p2.sex +" ,體重:"+p2.weight ); } }} 我是這么寫(xiě)的,可是編譯的時(shí)候說(shuō)我錯(cuò)了,非要把public class PersonTest{}改成public static class PersonTest{}或者把public static void main(String[] args) {}改成public void main(String[] args) {}才顯示正確。錯(cuò)誤提示是:The method main cannot be declared static; static methods can only be declared in a static or top level type 這是哪里出了問(wèn)題?我要怎么改呢? 展開(kāi)
全部評(píng)論(0條)
登錄或新用戶注冊(cè)
- 微信登錄
- 密碼登錄
- 短信登錄
請(qǐng)用手機(jī)微信掃描下方二維碼
快速登錄或注冊(cè)新賬號(hào)
微信掃碼,手機(jī)電腦聯(lián)動(dòng)
熱門(mén)問(wèn)答
- 測(cè)試類應(yīng)該怎么加啊??
- /*要求新建一個(gè)PersonTest測(cè)試類,對(duì)person類進(jìn)行測(cè)試*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args... /*要求新建一個(gè)PersonTest測(cè)試類,對(duì)person類進(jìn)行測(cè)試*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args) { // TODO Auto-generated method stub Person p1=new Person();//聲明并實(shí)例化Person類對(duì)象p1 Person p2=new Person();//聲明并實(shí)例化Person類對(duì)象p2 //給p1賦值 p1.name="張三"; p1.age=25; p1.address ="濟(jì)南"; p1.sex ='m'; p1.weight =100; //給p2賦值 p2.name ="李四"; p2.age =30; p2.address ="北京"; p2.sex ='w'; p2.weight =80; System.out.println("名字:"+p1.name +" ,年齡:"+p1.age +" ,家庭住址:"+p1.address +" ,性別:"+p1.sex +" ,體重:"+p1.weight ); System.out.println("名字:"+p2.name +" ,年齡:"+p2.age +" ,家庭住址:"+p2.address +" ,性別:"+p2.sex +" ,體重:"+p2.weight ); } }} 我是這么寫(xiě)的,可是編譯的時(shí)候說(shuō)我錯(cuò)了,非要把public class PersonTest{}改成public static class PersonTest{}或者把public static void main(String[] args) {}改成public void main(String[] args) {}才顯示正確。錯(cuò)誤提示是:The method main cannot be declared static; static methods can only be declared in a static or top level type 這是哪里出了問(wèn)題?我要怎么改呢? 展開(kāi)
- 這個(gè)代碼的測(cè)試類怎么寫(xiě)啊?
- public class q { String ys="黃色"; public void fs(){ System.out.println("正在以0.1米/秒的速度向前奔跑"); } public void qs(){ System.out.println("大聲吼叫!"); } public String ball(){ String ball="球"; return ball; ... public class q { String ys="黃色"; public void fs(){ System.out.println("正在以0.1米/秒的速度向前奔跑"); } public void qs(){ System.out.println("大聲吼叫!"); } public String ball(){ String ball="球"; return ball; } } 展開(kāi)
- java測(cè)試類怎么寫(xiě)測(cè)試類建立
- springboot怎么建測(cè)試類測(cè)試接口
- 測(cè)試類怎么傳httpservletrequest
- java測(cè)試類怎么寫(xiě)
- java里面的測(cè)試類是做什么用的?只要類名后面加一個(gè)text就叫測(cè)試類嗎?
- Java的測(cè)試類 怎么寫(xiě)
- public class Seller { String name; public Seller() { super(); } public Seller(String name) { super(); this.name = name; } public String getName() { return name; } public void setName(String name) { thi... public class Seller {
String name;
public Seller() {
super();
}
public Seller(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void sell1(Excelle excelle){
System.out.println("賣了一輛"+excelle.getType()+"id是"+excelle.getId());
}
public void sell2(Regal regal){
System.out.println("賣了一輛"+regal.getType()+"id是"+regal.getId());
}
public void sell3(Excelle excelle,int number){
System.out.println("我賣了"+number+"輛車");
for (int i=0;i2017-04-02 14:39:07 476 1
- Myeclipse中怎么編寫(xiě)測(cè)試類
- 如圖一個(gè)簡(jiǎn)單投票系統(tǒng)的網(wǎng)頁(yè), 編寫(xiě)兩個(gè)JSP,display負(fù)責(zé)顯示投票界面,vote負(fù)責(zé)接受用戶的投票,將對(duì)應(yīng)的教師的得票數(shù)加1,工作完成后再跳轉(zhuǎn)回diyi個(gè)JSP。就是第三點(diǎn),TestDao的代碼如何書(shū)寫(xiě)。
- testng eclipse 怎么寫(xiě)測(cè)試類
- Android studio怎么創(chuàng)建測(cè)試類
- spring boot 測(cè)試類怎么寫(xiě)
- java junit4測(cè)試類怎么寫(xiě)
- 關(guān)于java面向?qū)ο蟮膯卧獪y(cè)試。測(cè)試類應(yīng)該怎么寫(xiě)?具體代碼如下
- 測(cè)試類應(yīng)該怎么寫(xiě)。 public class Earth { public static void main(String args[]) { Monkey mary=new Monkey("Mary","red",100,120); Food banana=new Food("banana","veg",6); mary.showInfo(); mary.eat(banana); ... 測(cè)試類應(yīng)該怎么寫(xiě)。 public class Earth { public static void main(String args[]) { Monkey mary=new Monkey("Mary","red",100,120); Food banana=new Food("banana","veg",6); mary.showInfo(); mary.eat(banana); mary.piss(); mary.showInfo(); Human helen=new Human("Helen","white",100,170,"Obama"); Food hamberger=new Food("hamberger","meet",3); helen.showInfo(); helen.eat(hamberger); helen.piss(); helen.work(); helen.showInfo(); } } class Monkey { String name; String color; int weight; int height; int tempr; Monkey(String n,String c,int w,int h) { name=n;color=c;weight=w;height=h;tempr=0; } int eat(Food f) { int r; if (f.type.equals("veg")) { r=1*f.quantity; } else if (f.type.equals("meat")) { r=3*f.quantity; } else { r=0; } System.out.println("I'm eatting " + f.name + ", YUMMY!"); weight+=r; height-=r; tempr=r; return r; } int piss() { int r; if (tempr!=0) { Pee mypee=new Pee(tempr); r=mypee.weight; } else { r=0; } weight-=r; return r; } void showInfo() { System.out.println("I'm a " + color + " monkey, my name is: " + name + ", weight " + weight + ", height " + height + "."); } } class Food { String type; String name; int quantity; Food(String t,String n,int q) { type=t;name=n;quantity=q; } void showInfo() { System.out.println(name + ", " + type + ", " + quantity); } } class Pee { int weight; Pee(int w) { weight=w; } } class Human extends Monkey { String fname; Human(String n,String c,int w,int h,String f) { super(n,c,w,h); fname=f; } void work() { weight--; } void showInfo() { System.out.println("I'm a human, my name is: " + name + " " +fname + ", weight " + weight + ", height " + height + "."); } } 展開(kāi)
- C#編程測(cè)試類和非測(cè)試類
- 它們有什么區(qū)別,我初學(xué),我想知道到底我知道好似大部分方法放在非測(cè)試類,測(cè)試類應(yīng)該放些什么,感覺(jué)好似有規(guī)定的,因?yàn)槲覄倢W(xué)private 要用SetName初始化,我平時(shí)都是把所有的方法和賦值都放在非測(cè)試類,SetName豈不是廢了嗎。
- 壓力變送器接線應(yīng)該怎么接???
- myeclipse中怎么位某一個(gè)類建立一個(gè)測(cè)試類
- myeclipse中Junit測(cè)試類怎么在里面添加已有類?
4月突出貢獻(xiàn)榜
推薦主頁(yè)
最新話題





參與評(píng)論
登錄后參與評(píng)論