Java Flashcards
What are the four access modifiers in Java?
Private, protected, public and default (package).
What does the ‘private’ keyword do?
The private keyword is an access modifier, and variables, constructors or methods marked with the keyword ‘private’ can only be accessed by the code within the class.
What are can only variables, constructors methods be marked with the keyword ‘private’ and not classes?
This is because marking a class as private will mean that no other classes can access it, which fundamentally makes it useless in the overall program.
How can a privately declared variable or method be accessed by code outside of their declared class?
They can be accessed by using accessor methods, such as getters and setters.
How is the default access modifier declared and what does it allow for?
The default access modifier is declared by not declaring an access at all. This means that the variable, constructor, method or class can be accessed by code within the class itself as well as by the other classes in the package. Code outside of the package cannot access it.
What does the ‘protected’ keyword do?
The protected keyword is an access modifier that, just like the default access modifiers, allows code within the class and outside the class to access the protected variable or methods. Classes outside of the package to also have access. However this access is only available via child class.
What does the ‘public’ keyword do?
The public keyword allows for variables, methods and classes declared with the keyword be accessed by any class both inside and outside the package.
What is an Object?
Objects are instances of classes, and is an entity that has attributes, behaviour and identity.
What is a Class?
A class is a template that describes all the attributes of objects as well as the methods that implement the behaviour of member objects. It also serves as a template that describes the properties, state, and behaviours common to a particular group of objects.
What is multi-threading?
Multithreading is a type of execution model that allows multiple threads to exist within the context of a process such that they execute independently but share their process resources.
What are references?
References are addresses that indicate where an objects variable and methods are stored in memory.
What are the functions of JVM, and JRE?
The JVM provides a platform-independent runtime environment for Java Byte codes to be executed, whilst the JRE includes sets of files required by the JVM during runtime.
What is the difference between overloading and overriding?
When there are two methods of the same name but different properties, it is overloading. Overriding occurs when there are two methods of the same name and properties, and one is in the child class and the other is in the parent class.
What is the difference between equals() and ==?
Equals is a method used for checking the equality of two objects defined by business logic, whilst == is an operator used to compare primitives and objects.
What are contructors?
Constructors are blocks of code used to initialise an object.