Java Classes Flashcards
What is object oriented programming?
object-oriented programming is about creating objects that contain both data and methods
What are classes in Java?
A Class is like an object constructor, or a “blueprint” for creating objects.
What is an object?
An object is an instance of a class. You would instantiate an object which would call the constructor of the object and then depending on the parameters involved you would set the variables and then have access to the methods.
What are Java Class Attributes?
Attributes are variables within a class and can be any of the data types
How would you access attributes in an object?
You can access attributes by creating an object of the class, and by using the dot syntax (.):
How do you modify an attribute?
By using the assignment operator = after the object is created
How does the keyword final affect an attribute in a class?
It makes it so you can’t modify the value.
How would you call a static method in a class?
Would simply call the method myStaticMethod(); in the main method
How would you call a non-static method?
Would need to first create an object and then use the dot notation to access the method.
What is a constructor in Java?
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created. It can be used to set initial values for object attributes
What are constructor parameters?
Constructors can also take parameters, which is used to initialize attributes. Parameters are data that is passed into the object to set attributes or for method calls.
What are the two types of modifiers for methods in Java?
1- Access
2 - Non-access
What are the different access modifiers for classes, methods, and attributes?
For classes, you can use either public or default. For attributes, methods and constructors, you can use the one of the following
What are the different non-access modifiers for classes, methods, and attributes?
For classes, you can use either final or abstract. For attributes and methods, you can use the one of the following
What is a static method?
A static method means that it can be accessed without creating an object of the class, unlike public