Topic: 一个简单问题 |
Print this page |
1.一个简单问题 | Copy to clipboard |
Posted by: zyy266 Posted on: 2004-09-27 09:50 import java.io.*; class Elevator{ boolean running = true; void shutDown(){ running = false; } class FrontDesk{ private final int EVENING = 8; Elevator NorthElevator, SouthElevator; FrontDesk() { NorthElevator = new Elevator(); SouthElevator = new Elevator(); } void maintenance(int time){ if(time==EVENING) NorthElevator.shutDown(); } void displayStatus(){ System.out.print("North Elevator is "); if(!(NorthElevator.running)) System.out.print("not"); System.out.println("running."); System.out.print("South Elevator is "); if(!(SouthElevator.running)) System.out.print("not"); System.out.println("running."); } } } public class Hotel{ public static void main(String args[]){ FrontDesk lobby; lobby = new FrontDesk(); System.out.print("It's 7:00 tTime to check the "); lobby.maintenance(7); lobby.displayStatus(); System.out.println(); System.out.println("It's 8:00 Time to cheack the "); lobby.maintenance( 8 ); lobby.displayStatus(); } } 这个程序编译出错 显示 D:\rabbit\java\exercise\Hotel.java:35: cannot resolve symbol symbol : class FrontDesk location: class Hotel FrontDesk lobby; ^ D:\rabbit\java\exercise\Hotel.java:36: cannot resolve symbol symbol : class FrontDesk location: class Hotel lobby = new FrontDesk(); 难道这里定义方法有错? |
2.Re:一个简单问题 [Re: zyy266] | Copy to clipboard |
Posted by: 极品飞车 Posted on: 2004-09-27 14:10 前面两个类不以}结束. |
3.Re:一个简单问题 [Re: zyy266] | Copy to clipboard |
Posted by: cjf_28040 Posted on: 2004-09-27 15:05 内嵌类的不能在类外被声明 |
4.Re:一个简单问题 [Re: zyy266] | Copy to clipboard |
Posted by: zyy266 Posted on: 2004-09-28 09:38 不用{} 该用什么 |
5.Re:一个简单问题 [Re: zyy266] | Copy to clipboard |
Posted by: gooood Posted on: 2004-09-28 17:30 正确的写法应该为 import java.io.*; class Elevator{ boolean running = true; void shutDown(){ running = false; } } class FrontDesk{ private final int EVENING = 8; Elevator NorthElevator, SouthElevator; FrontDesk() { NorthElevator = new Elevator(); SouthElevator = new Elevator(); } void maintenance(int time){ if(time==EVENING) NorthElevator.shutDown(); } void displayStatus(){ System.out.print("North Elevator is "); if(!(NorthElevator.running)) System.out.print("not"); System.out.println("running."); System.out.print("South Elevator is "); if(!(SouthElevator.running)) System.out.print("not"); System.out.println("running."); } } public class HotelElevator{ public static void main(String args[]){ FrontDesk lobby; lobby = new FrontDesk(); System.out.print("It's 7:00 tTime to check the "); lobby.maintenance(7); lobby.displayStatus(); System.out.println(); System.out.println("It's 8:00 Time to cheack the "); lobby.maintenance( 8 ); lobby.displayStatus(); } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |