#2 Random Questions for practice on Basic Java Programing
#2 Random Questions for practice on Basic Java Programing Q #11) What is Encapsulation? Answer: Purpose of Encapsulation: · Protects the code from others. · Code maintainability. · Wrapping of details · Can be achive by getter and setter Example: We are declaring ‘a’ as an integer variable and it should not be negative. public class Addition(){ int a=5; } If someone changes the exact variable as “ a = -5” then it is bad. In order to overcome the problem we need to follow the steps below: · We can make the variable private or protected. · Use public accessor methods such as set<property> and get<property>. So that the ab...