1- Please explain the differences between the private, protected, and public acc
ID: 3825731 • Letter: 1
Question
1- Please explain the differences between the private, protected, and public access modifiers.
2-
Given the definitions,
Scanner kb;
kb = new Scanner(System.in);
int a = kb.getNextInt();
Describe what's going on these statements.
3-Briefly explain the purpose and functionality that ArrayList classes and functions provide to a programmer.
4-
Here is a function that uses a for loop. Write a function that does the same thing, but using a do while loop. Be sure you write the correct number of copies of the cheer, “Hip, Hip, Hurray!”.
Explanation / Answer
Answer:
1)
· A private member is only accessible within the same class as it is declared.
.
· A protected member is accessible within all classes in the same package and within subclasses in other packages.
· A public member is accessible to all classes (unless it resides in a module that does not export the package it is declared in).
2) A scanning operation may block waiting for input.
The java.util.Scanner.nextInt() method Scans the next token of the input as an int.An invocation of this method of the form nextInt()
3) ArrayList class provides resizable-array and implements the List interface
4)
public void cheers(int n){
int i = 0;
do{
System.out.print( “Hip, Hip, Hurray!”);
i++;
}while(i<n);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.