Vous êtes sur la page 1sur 4

1.

Super class

package college;

abstract class college1 {

String name ;

String department;

public college1() {

name = "salaeh";

department = "d. mohamed";

public college1(String nam,String dep) {

name = nam;

department = dep;

abstract void fun();

2. Subclass (students):
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package college;

/**
*
* @author AHMED
*/
public class student extends college1 {
public student(){
super();
}

public student(String student_name,String student_dep){


super(student_name,student_dep);
}
void fun(){
System.out.println("abstract function");

}
public void inform (String nam){
System.out.println("student name is");
System.out.println(nam);
}
public void inform (String nam,String dep){
System.out.println("student name is");
System.out.println(nam);
System.out.println("student depart is");
System.out.println(dep);
}

3. Subclass (doctors)

package college;

public class doctors extends college1 {


String doctor_name;
String doctor_depart;
void fun(){
System.out.println("abstract function");

}
public doctors() {
super();
}
public doctors(String doctor_name, String doctor_depart) {
super(doctor_name,doctor_depart);
}
public void inform (String nam){
System.out.println("doctor name is");
System.out.println(nam);
}
public void inform (String nam,String dep){
System.out.println("doctor name is");
System.out.println(nam);
System.out.println("doctor depart is");
System.out.println(dep);
}
}

4. Class test

package college;

public class test {


public static void check(Object obj){

if (obj instanceof doctors){


System.out.println("this is doctor class ");

}
if (obj instanceof doctors){
System.out.println("this is student class ");
}}
public static void main(String[] args){
doctors doc;
doc = new doctors();
check(doc);
doc.fun();
doc.inform(doc.name, doc.department);

student st;
st = new student();
check(st);
doc.fun();
doc.inform(st.name, st.department);
}