<JAVA PROGRAMMING> 1. How do tou prevent a class from being extended? How do pre
ID: 3862389 • Letter: #
Question
<JAVA PROGRAMMING>
1. How do tou prevent a class from being extended? How do prevent a method from being overriden?
(single word answer)
---------------------------------------------------------------------------------------------------------
2. What will be displayed by the following code?
class Test {
public static void main (String[] args){
int[] list 1 = {3,2,1};
int[] list 2 = {1,2,3};
list 2 = list 1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = list2.length - 1; i > = 0; i --)
System.out.print(list2[i] + "");
}
}
Explanation / Answer
Questoin 1:
to prevent a class from being extended,to prevent a method from being overriden we precede that class or method definition with the final attribute.
Example class:
final public class A {
}
Example method:
final public function m () {
}
Question 2:
Answer is : 210
list2 = list1; the values in list1 are same as value in list2 so if we change the value in list1 it will effect to list2 and vise versa
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.