1) conceptually a class represents the behaviour of something. An instance of a class is an object. Objects typically represent state, and the methods for an object typically control and ensure the object's integrity (correctness). To set the state of an object you usually call a function defined for that object with a new value, and the function would ensure that the value is correct, also ensuring the state of the object is correct.
Example: you have a class Calendar, which would represent a calendar. One possible value that a Calendar object could store is the current month, which would be represented as an integer value between 1 and 12 (there are other ways to represent this, but let's just roll with this example). If the member variable were public, allowing external users of the object write access, it would be possible to set this variable to an invalid value, whereas if it were private and accessed with getter/setter functions int getMonth()
/void setMonth(int month)
, the function implementation would ensure that only correct values would be set for the month. You could potentially write code in calling functions to ensure that the value being written to the month variable in the calendar is valid, but this would lead to repetition and duplication of code which is considered bad design.
2) best to look at this from a GUI perspective example: mouse actions. Possible mouse actions example: mouse click. Your program can be written in such a way to listen for mouse clicks: the action of performing a mouse click raises an event. A listener is a class/function that would run based on events that it receives.