مشكلتي اليوم في بناء الكلاس و استدعاءها
هي سهلة جدا على الكثير من المتعمقين في الجافا
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
/**
*
* @author Administrator
*/
public class Demo {
public static void main(String[] args) {
Person person = new Person();
person.setName("Patrice");
System.out.println(person);
Person person2 = new Person("Stewrt",23);
System.out.println(person2);
}
}/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
/**
*
* @author Administrator
*/
public class Person {
// varible
private String name;
private int age;
// constractor
public Person() {
name = "Defailt Name";
age = 10;
}
public Person(String theName, int theAge) {
this.age = age;
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("\nName: " + this.name);
sb.append("\nAge: " + this.age );
return sb.toString();
}
}
