Overriding toString() in Java Assignment

Added on - 17 Oct 2019

  • 5

    Pages

  • 849

    Words

  • 124

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 2 of 5 pages
Project NameUniversity Name , with addressDateSubmitted By –
Ques 1packageques1;public classPerson {privateStringname;privateStringaddress;publicPerson(String name, String address) {this.name= name;this.address= address;}publicPerson(){}@OverridepublicString toString() {return"name='"+name+"', address='"+address+"' ";}public voidsetAddress(String address) {this.address= address;}publicString getName() {returnname;}publicString getAddress() {returnaddress;}}Ques 2packageques2;importques1.Person;public classStaffextendsPerson {privateStringschool;private doublepay;publicStaff(String name, String address, String school,doublepay) {super(name, address);this.school= school;this.pay= pay;}publicString getSchool() {returnschool;}public voidsetSchool(String school) {this.school= school;}public doublegetPay() {returnpay;}public voidsetPay(doublepay) {this.pay= pay;}
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document