Skip to content

Instantly share code, notes, and snippets.

@mangkoran
Created April 7, 2021 03:28
Show Gist options
  • Save mangkoran/40f8649876583906cdf06337911e59c2 to your computer and use it in GitHub Desktop.
Save mangkoran/40f8649876583906cdf06337911e59c2 to your computer and use it in GitHub Desktop.
// Name: Afiq Nazrie Rabbani
// Matric: A19EC0216
class TrialTest {
public static void main(String[] a) {
Trial ac = new Trial(5, "Five");
// ac.a = 10; //The field Trial.a is not visible
// ac.b = "Ten"; //The field Trial.b is not visible
ac.setAB(10, "Ten"); //Use setter
ac.setAB(6, "Six");
// getA(); //Cant find method getA()
ac.show();
// show(); //Cant find method show()
// ac.getA(); //The method getA() from the type Trial is not visible
}
}
class Trial {
private int a;
private String b;
public Trial(int _a, String _b) { // Add argument
a = _a;
b = _b;
}
public void setAB(int num, String str) {
a = num;
b = str;
}
private int getA() {
return a;
}
public void show() {
System.out.println("A: "+ getA());
System.out.println("B: "+ b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment