Rumah >Java >javaTutorial >Dayinheritance:
WARISAN:
* Inheritance is implemented using the extends keyworrds. * Inheritance in java is a mechanism where one class child or subclass acquires the properties and behaviors fields and methods of another class parent or superclass. * subclass (child) - the class that inherits from another class * superclass (parent) - the class being inherited from To inherit from a class, use the extends keyword. #
Contoh program:
package reegan; class Dad
{
wang int=2000;
}
anak kelas memanjangkan ayah
{
}
kelas utama kelas awam
{
utama kekosongan statik awam(String []args)
{
anak s1=anak baru();
System.out.println(s1.money);
}
}
Atas ialah kandungan terperinci Dayinheritance:. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!