Created
April 7, 2021 03:28
-
-
Save mangkoran/40f8649876583906cdf06337911e59c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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