0% found this document useful (0 votes)
21 views4 pages

Superclass and Subclass Implementation

1. The document defines a College abstract superclass with name and department fields and constructors. It also defines an abstract fun() method. 2. A Student subclass extends the College superclass and overrides the fun() method to print a message. It also contains inform methods to print student name and name/department. 3. A Doctors subclass also extends the College superclass and overrides fun() and contains inform methods like the Student class. 4. A Test class contains a check method to check object types and a main method that creates Doctor and Student objects, calls check and inform methods.

Uploaded by

osama yosif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Superclass and Subclass Implementation

1. The document defines a College abstract superclass with name and department fields and constructors. It also defines an abstract fun() method. 2. A Student subclass extends the College superclass and overrides the fun() method to print a message. It also contains inform methods to print student name and name/department. 3. A Doctors subclass also extends the College superclass and overrides fun() and contains inform methods like the Student class. 4. A Test class contains a check method to check object types and a main method that creates Doctor and Student objects, calls check and inform methods.

Uploaded by

osama yosif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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(){
[Link]("abstract function");

}
public void inform (String nam){
[Link]("student name is");
[Link](nam);
}
public void inform (String nam,String dep){
[Link]("student name is");
[Link](nam);
[Link]("student depart is");
[Link](dep);
}

3. Subclass (doctors)

package college;

public class doctors extends college1 {


String doctor_name;
String doctor_depart;
void fun(){
[Link]("abstract function");

}
public doctors() {
super();
}
public doctors(String doctor_name, String doctor_depart) {
super(doctor_name,doctor_depart);
}
public void inform (String nam){
[Link]("doctor name is");
[Link](nam);
}
public void inform (String nam,String dep){
[Link]("doctor name is");
[Link](nam);
[Link]("doctor depart is");
[Link](dep);
}
}

4. Class test

package college;

public class test {


public static void check(Object obj){

if (obj instanceof doctors){


[Link]("this is doctor class ");

}
if (obj instanceof doctors){
[Link]("this is student class ");
}}
public static void main(String[] args){
doctors doc;
doc = new doctors();
check(doc);
[Link]();
[Link]([Link], [Link]);

student st;
st = new student();
check(st);
[Link]();
[Link]([Link], [Link]);
}

You might also like