الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مجرد توضيخ ب opp

مغلق
بدأه CS25 في 20 نوفمبر 2006 · 1 رد · 463 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

عندي هذا البرنامج

class Student {

	 public static String name;  
	 private static int serialNumber;
	 public static int numOfStudents = 0;

	 public Student(String _name) {
		name = _name;
		serialNumber = numOfStudents++;
	 }

	 public static int getSerial() {
	 	return serialNumber;
	 }

 }

 /*public*/ class MainClass {
	public static void main(String[] args) {

	  System.out.printf("We now have %d students.\n",Student.numOfStudents);
	  Student A = new Student("Adam");
	  Student B = new Student("Bob");
	  System.out.printf("We now have %d students.\n",Student.numOfStudents);
	  Student C = new Student("Cathy");
	  System.out.printf("We now have %d students.\n",C.numOfStudents);

	  new Student("xxxx");  
	  System.out.printf("We now have %d students.\n",A.numOfStudents);

	  System.out.println(A.name);
	  System.out.println(B.name);
	  System.out.println(C.name);
		System.out.println(Student.name);


	  System.out.printf("serial = %d \n",A.getSerial());   //Student.getSerial()



   }
 }

لمن ابي اطبع الاسامي دائما يطبع الاسم xxxx اليس المفروض العناصر A & B & C تطبع كل اسم اسند اليها بصراحه هالمثال لخبط علي مفاهيم opp ممكن احد يفسرلي ليش هالشي صار.

#2

لانك عرفت المتغيرات nameو serialNumber على انها static حدث الخطا الغير متوقع

هذا الموضوع مغلق.

مواضيع مشابهة