0

What is tue different between 1 and 2??

1)public class Marks { private String color; public String getMark() { return color; } public void setApp(String x) { this.color = x; } } public class Program { public static void main(String[] args) { Marks v = new Marks(); v.setApp("strong"); System.out.println(v.getMark()); } } 2)public class Marks { public String getMark() { return color; } public void setApp(String x) { this.color = x; } } public class Program { public static void main(String[] args) { Marks v = new Marks(); v.setApp("strong"); System.out.println(v.getMark()); } }

9th Jul 2021, 4:37 PM
Shahir
Shahir - avatar
2 Answers
0
2nd one is missing declaration of variable color.
9th Jul 2021, 4:42 PM
Abhay
Abhay - avatar
0
In 2nd you dont have color variable. Then how can u use getter and setter (getMark(), setMatk()) on it. Because these two methods assign and return the color variable. Your 2nd program shows error
11th Jul 2021, 2:16 AM
Jawahirullah
Jawahirullah - avatar