עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

שאלה|בנוגע למערך של עצמים בג'אווה.

Featured Replies

פורסם

אני פותר תרגיל בג'אווה אבל יש לי בעיית קומפילציה עם מערך של עצמים שבניתי..

זהו הבנאי של העצם: (שם העצם הוא Rabbit)

public Rabbit (double s1,double s2,double s3,String name)

{

score1=s1;

score2=s2;

score3=s3;

this.name=name;

avg=(s1+s2+s3)/3.0;

}

זהו השלב שבו יצרתי את המערך:

int rabbits=in.nextInt();

Rabbit [] ra=new Rabbit [rabbits];

וזהו השלב שזימנתי את הבנאים (זה בתוך לולאה):

System.out.println("Please Enter Rabbit's Name");

name=in.next();

System.out.println("Please Enter All 3 Scores:");

s1=in.nextDouble();

s2=in.nextDouble();

s3=in.nextDouble();

ra=new Rabbit(s1,s2,s3,name);

והבעיה שלי לפי הקומפיילר היא בקטע הזה:

ra=new Rabbit(s1,s2,s3,name);

השגיאה:

non-static variable this cannot be referenced from a static context

מה הבעיה? תודה מראש..

פורסם

אני מניח שאתה עושה הכל ב main שהיא פונקציה סטטית

אתה לא יכול לגשת למשתנה לא סטטי שנמצא במחלקה שלך מפונקציה סטטית במחלקה אלא אם המשתנה הוא סטטי

פורסם

ג'אווה = שפה עילית. הועבר לפורום המתאים.

ערוך בבקשה את ההודעה ושים את הקוד בתוך טג קוד (כפתור שנראה כמו #) כדי שיהיה קריא יותר.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.