Java Basics Flashcards
1
Q
Method Overloading
A
- (if a class has) multiple methods having the same name but different parameters
- it increases the readability and reusability of the program
- there are two ways to overload the method: changing the number of arguments; changing the data type
- a good example is System.out.println() method
2
Q
Constant
A
- it is a value that can’t be changed after assigning it
- We use static and final modifiers (aka non-access modifiers), to declare any variable as constant
- its identifier name must be in capital letters
3
Q
“final” keyword
A
- it is a non-access modifier applicable only to a variable, a method, or a class
- when a variable is declared with the final keyword, its value can’t be modified.
- when a method is declared with the final keyword, it can’t be overridden.
- when a class is declared with the final keyword, it can’t be extended (inherited).
4
Q
Modifiers
A
- are specific keywords that we can use to make changes to the characteristics of a variable, method, or class and limit its scope
- Java has two types of modifiers: access modifiers and non-access modifiers
5
Q
Non-Access Modifiers
A
- provide information about the characteristics of a class, method, or variable.
6
Q
What are the seven types of Non-Access Modifiers?
A
- static
- final
- abstract
- synchronized
- volatile
- transient
- native
7
Q
static methods
A
- when a method is declared with the static keyword, it is known as the static method
- Any static member can be accessed before any objects of its class are created and without reference to any object.
- the most common example of a static method is the main() method
8
Q
What are the restrictions of the static methods?
A
- they can only directly call other static methods
- they can only directly access static data
- they can’t refer to this or super in any way
9
Q
private keyword
A
an access modifier used for attributes, methods, and constructors, making them only accessible within the declared class
10
Q
protected keyword
A
used for attributes, methods, and constructors, making them accessible in the same package and subclasses
11
Q
int vs. Integer
A
- int is a primitive data type while Integer is a type of class
12
Q
“new” keyword
A
- it is used to create an instance of the class.
- it instantiates a class by allocating memory for a new object and returning a reference to that memory.
- we can also use the new keyword to create the array object
13
Q
What are the two types of data types Java provides?
A
- primitive
- reference
14
Q
Examples of reference data types
A
- Array
- class
- interface
- String
- Enumeration
- Annotations
15
Q
Serializable
A
In Java, it is a marker (empty) interface and has no fields or methods to implement.