java中不區(qū)分大小寫所以你把pen類改個名字
在廣德等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需定制開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,外貿(mào)網(wǎng)站制作,廣德網(wǎng)站建設(shè)費(fèi)用合理。
還有你的主函數(shù)名字寫錯了,不是'mina'而是'main',正確代碼如下:
class abc{
double cuxi;
double moshui;
String yanse;
boolean bimao;
int chang,banjing;
void hua(){
System.out.println("畫圖");
}
void xie(){
System.out.println("寫字");
}
void geng(){
System.out.println("更換墨水");
}
}
public class Pen{
public static void main(String[] args){
abc pen1;
pen1=new abc();
pen1.cuxi=1.5;
pen1.moshui=300.0;
pen1.yanse="黑色";
pen1.bimao=true;
pen1.chang=10;
pen1.banjing=1;
System.out.println("粗細(xì):"+pen1.cuxi);
System.out.println("墨水:"+pen1.moshui);
System.out.println("顏色:"+pen1.yanse);
if(pen1.bimao)System.out.println("有筆帽");
else System.out.println("無筆帽");
System.out.println("長度:"+pen1.chang);
System.out.println("半徑:"+pen1.banjing);
pen1.hua();
pen1.xie();
pen1.geng();
}
}
class Person{
private String name;
private Person friend;
Person(String name){
this.name=name;
}
void setFriend(Person friend){
this.friend=friend;
}
String getName(){
return name;
}
String getFriendName(){
return friend.name;
}
}
public class Self1{
public static void main(String[] args){
Person man1=new Person("aaa");
Person man2=new Person("bbb");
man1.setFriend(man2);
man2.setFriend(man1);
System.out.println(man1.getName()+"'sfriend"+man1.getFriendName());
System.out.println(man2.getName()+"'sfriend"+man2.getFriendName());
}
}
這樣就可以了。你把最后的那個大括號放到Self1這個類的上面,不然編譯器就把Self1這個類當(dāng)作是Person類的內(nèi)部類。
//都已改好
import java.util.*;
class Student {
int num;
String name;
float grade;
public Student() {}
public Student(int stuNum,String stuName,float stuGrade) {
num = stuNum;
name = stuName;
grade = stuGrade;
}
public void showGrade() {
System.out.println("姓名: " + name);
System.out.println("成績: " + grade);
}
}
public class Test {
private static ListStudent stuList = new ArrayListStudent();
public static void main(String[] args) {
Student xiaoming = new Student(1, "小明", 70);
stuList.add(xiaoming);
test(1);
}
public static void test(int num) {
boolean isStuExist = false;
for(Student stu : stuList) {
if(num == stu.num) {
stu.showGrade();
isStuExist = true;
}
}
if(isStuExist) {
System.out.println("存在該學(xué)號的學(xué)生");
}
}
}