Further use of abstract classes

Source: Internet
Author: User

Abstract class person {

Private string name;
Private int age;
 
Public Person (string name, int age ){

This. setname (name );
This. setage (AGE );
}

Public void setname (string name ){

This. Name = Name;
}
Public String getname (){
 
Return name;
}

Public void setage (INT age ){

This. Age = age;
}

Public int getage (){

Return age;
}

Public void say (){

System. Out. println (this. getcontent ());
}
Public abstract string getcontent ();
}

Class student extends person {

Private string branch;

Public student (string name, int age, string Branch ){

Super (name, age );
This. setbranch (Branch );
}
 
Public void setbranch (string Branch ){

This. Branch = branch;
}
Public String getbranch (){

Return branch;
}

Public String getcontent (){

Return "name:" + super. getname () + "/t" + "Age:" + super. getage () + "/t" + "Don't:" + this. getbranch ();
}
}

Class worker extends person {

Private string department;

Public worker (string name, int age, string Department ){

Super (name, age );
This. setdepartment (Department );
}
 
Public void setdepartment (string Department ){

This. Department = Department;
}
 
Public String getdepartment (){

Return department;
}

Public String getcontent (){

Return "name:" + super. getname () + "/t age:" + super. getage () + "/T Department:" + this. Department;
}
}

Public class oodemo09 {

Public static void main (string [] ARGs ){

Person P = new worker ("Java", 15, "Technology Department ");
P. Say ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.