Week 2 Objects Flashcards
What do objects allow us to do?
Bring together variables and methods into a single thing
What is the science of Java programming?
rules and syntax for making objects
What is the art of Java programming?
Which variables and methods to bring together
Scanner object - describe it
Has its own internal variable - stores it
What is encapsulation?
use an object without understanding the underlying code
What is java swing?
a package that helps you make a window
Generally, what does a class have?
- a name (starting with a capital letter)
- some variables (class atttributes that belong to the class)
- some methods
- a constructor method that allows you to create a new object
- each class defined in its own file
What does public mean?
it is a modifier that describes to which other objects they are visible.
All classes, class attributes and class methods have a modifier
public is visible by anything
What does private mean?
these classes, attributes and methods can only be used by the class in which they are defined
i.e. can only be accessed within the class
What does protected mean?
can be used only by other classes in the same package or that inherit from this class
Are attributes private or public, generally speaking?
private
it maintains the integrity of the object - doesn’t allow other bits of the program to change the object in any way
What are getter and setter methods?
they allow parts of the program to access and change attributes
you apply them to the variables
this
use this in a class to refer to class attributes
e. g.
this. radius = radius;
When 2 attributes co-exist, if we don’t use this, the local one (the one passed to the method) is used
What does static mean?
optional keyword, allows us to have class attributes and methods that can be accessed without creating an instance of the class i.e. an object
if not creating an object and influencing its methods, use static.. - static method as not doing anything to an object.
useful when we want to access methods without the overhead of making objects from that class
What can be static?
attributes and methods!
*static attributes take the same value for all instances of a class and all objects made from that class e.g. pi = 3.14…
anytime we change the static variable, it changes it for all of them!