第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

公共類型 Main 必須在其自己的文件中定義

公共類型 Main 必須在其自己的文件中定義

千萬里不及你 2021-10-20 15:23:47
public interface Shape { } class Circle implements Shape {     Circle(int radius) { /* ... */ } } class Rectangle implements Shape {     Rectangle(int height, int width) { /* ... */ } } public class Main {     public static void main (String[] args) {         Shape[] shapes = new Shape[2];         shapes[0] = new Circle(1);         shapes[1] = new Rectangle(1, 2);         writeShapes(shapes);     }     public static void writeShapes(Shape[] shapes){         for(Shape shape:shapes){             if(shape instanceof Circle) System.out.println("Circle");             else if(shape instanceof Rectangle) System.out.println("Rectangle");         }     } 在示例中,我想添加新形狀。但是,我無法理解在我的 main 方法中發(fā)生的錯誤“公共類型 Main 必須在其自己的文件中定義”是怎么回事。我試圖在 main 前面添加“靜態(tài)”,但它不起作用!任何建議表示贊賞!
查看完整描述

2 回答

?
海綿寶寶撒

TA貢獻1809條經(jīng)驗 獲得超8個贊

一個.java文件只能包含一個公共類/接口。

在您的情況下,您可以將Main類或Shape接口移動到另一個文件。


查看完整回答
反對 回復 2021-10-20
  • 2 回答
  • 0 關(guān)注
  • 382 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號