0% found this document useful (0 votes)
11 views2 pages

Assignment On Instance Variable and Methods

Uploaded by

Siam Ahmed
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)
11 views2 pages

Assignment On Instance Variable and Methods

Uploaded by

Siam Ahmed
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
You are on page 1/ 2

Instance variable and writing methods

Answer of 1 , 2 & 3:

Bold lines are added to the code according to the questions.


package bicycleregistration;

public class Bicycle {

private String ownerName, tagNo;

public Bicycle() {
this.ownerName = "Unknown";
this.tagNo = "Unknown";
}

public String getOwnerName() {


return ownerName;
}

public void setOwnerName(String name) {


this.ownerName = name;
}

public String getTagNo() {


return tagNo;
}

public void setTagNo(String tagNo) {


this.tagNo = tagNo;
}

package bicycleregistration;

public class BicycleRegistration {

public static void main(String[] args) {


Bicycle bike1 = new Bicycle();
bike1.setOwnerName("Abdullah Saleh Muhammed");
bike1.setTagNo("2010- 134R");
// create and assign values to bike2

Bicycle bike2 = new Bicycle();


bike2.setOwnerName("Abdul Karim Chowdhury");
bike2.setTagNo("2019 - 789X");
String owner1, owner2, tag1, tag2;

//output the information


owner1 = bike1.getOwnerName();
owner2 = bike2.getOwnerName();

tag1 = bike1.getTagNo();
tag2 = bike2.getTagNo();

System.out.println(owner1 + " owns a bicycle of tag no:" + tag1);


System.out.println(owner2 + " also owns a bicycle of tag no:" + tag2);
} // end of main method

You might also like