package package1;public class App{ public int VarPublic; private int VarPrivate; protected int VarProtected; int VarPackage; public App(String str){ System.out.println(str); } public void message(){ System.out.println("hello world!"); }}-----------------------------------------package package2;import package1.App;public class Apps extends App{ public int VarPublic; public Apps(String str) { super(str); super.VarPublic=4; this.VarPublic=3; //TODO Auto-generated constructor stub } public void message(){ super.message(); System.out.println("je suis moad aitaayi"); } public static void main(String[] args) { Apps app1= new Apps("l héritage en java"); app1.message(); }}affiche: l héritage en java hello world! je suis moad aitaayi
package package1;
public class App{
public int VarPublic;
private int VarPrivate;
protected int VarProtected;
int VarPackage;
public App(String str){
System.out.println(str);
}
public void message(){
System.out.println("hello world!");
-----------------------------------------
package package2;
import package1.App;
public class Apps extends App{
public Apps(String str) {
super(str);
super.VarPublic=4;
this.VarPublic=3;
//TODO Auto-generated constructor stub
super.message();
System.out.println("je suis moad aitaayi");
public static void main(String[] args) {
Apps app1= new Apps("l héritage en java");
app1.message();
affiche:
l héritage en java
hello world!
je suis moad aitaayi
0 تعليقات