السلام عليكم
كتبت هذا البرنامج التالي(يتألف من ثلاث صفوف عادية لايوجد بينها وراثة و لا أي شيء) :
/***********building class**********/
class Building
{
//المتحولات الخاصة بالصف
private int floor,rooms,sqmeter;
//الباني العادي
Building(int floor,int rooms,int sqmeter)
{
this.floor=floor;
this.rooms=rooms;
this.sqmeter=sqmeter;
}
//الباني الافتراضي
Building()
{
this.floor=0;
this.rooms=0;
this.sqmeter=0;
}
void export()
{
System.out.println("building info:\n floors:"+floor+" rooms:"+rooms+" sqmeter:"+sqmeter);
}
public static void main(String args[])
{
/*class-1- test*/
Building b1=new Building();
Building b2=new Building(5,10,200);
b1.export();
b2.export();
}
}//نهاية الصف
/**********House class*************/
class House
{
private int bedrooms,bathrooms;
//الباني العادي
House(int bedrooms,int bathrooms)
{
this.bedrooms=bedrooms;
this.bathrooms=bathrooms;
}
//الباني الافتراضي
House()
{
this.bedrooms=0;
this.bathrooms=0;
}
void export()
{
System.out.println("house info:\n bedrooms:"+bedrooms+" bathrooms:"+bathrooms);
}
//public static void main(String args[])
//{
// House o1=new House();
// House o2=new House(5,6);
// o1.export();
// o2.export();
//}
}//نهاية الصف
/**************class office*************/
class Office
{
private int phones,extnguishers;
//الباني العادي
Office(int phones,int extnguishers)
{
this.phones=phones;
this.extnguishers=extnguishers;
}
Office()
{
this.phones=0;
this.extnguishers=0;
}
void export()
{
System.out.println("office info:\n phones:"+phones+" extnguishers:"+ extnguishers);
}
// public static void main(String args[])
//{
//Office o1=new Office();
// Office o2=new Office(5,6);
// o1.export();
// o2.export();
//}
}
/*class Test
{
public static void main(String args[])
{
Building b1=new Building();
Building b2=new Building(5,10,200);
b1.export();
b2.export();
House h1=new House();
House h2=new House(5,6);
h1.export();
h2.export();
Office o1=new Office();
Office o2=new Office(5,6);
o1.export();
o2.export();
}
}*/و في هذه الصيغة الحالية استطعت اختبار الصف الأول و لكن عندما حاولت وضع صف جديد test يحوي على main method فقط لإنشاء أغراض من الصفوف الثلاثة أخرج لي خطأ و قال أن ها البرنامج لا يملك static public main methd
علماً أنه كانت صياغة الصف test كالآتي :
class Test
{
public static void main(String []args )
{
Building b1=new Building(10,10,10);
House h1=new House(10,10);
Office o1=new Office(10,10);
b1.export();
11.export();
o1.export();
}
}
فما الخطأ علماً أني الآن لا أريد استخدام الوراثة .
...