My Fault Book 687
My Fault Book 687
Question (1)
1. class A {
2. public static void main (String[] args) {
3. byte a[] = new byte[2];
4. long b[] = new long[2];
5. float c[] = new float[2];
6. Object d[] = new Object[2];
7. System.out.print(a[1]+”,”+b[1]+”,”+c[1]+”,”+d[1]);
8. } }
1|Page
Fayoum University 1st year | Software Engineering 1
Faculty of Engineering Time allowed: 1.5hrs | May 2022
Computer & Systems Eng. Dept. Examiner: Dr. Sayed Taha
1. interface Count {
2. short counter = 0;
3. void countUp( );
4. }
5. public class TestCount implements Count {
6.
7. public static void main(String[] args) {
8. TestCount t = new TestCount( );
9. t.countUp( );
10. }
11. public void countUp( ) {
12. for (int x = 6; x > counter; x--, ++counter) {
13. System.out.println(“ “ + counter);
14. }
15. }
16. }
What is the result?
A. 1 2 3 B. 0 1 2 3 C. 1 2 3 4
D. Compiler error. Because the variable type of counter is final static.
E. Compiler error. The method countUp( ) has no implementation in interface Count.
2|Page
Fayoum University 1st year | Software Engineering 1
Faculty of Engineering Time allowed: 1.5hrs | May 2022
Computer & Systems Eng. Dept. Examiner: Dr. Sayed Taha
1. class Pizza {
2. java.util.ArrayList toppings;
3. public final void addTopping(String topping) {
4. toppings.add(topping);
5. }
6. }
7. public class PepperoniPizza extends Pizza {
8. public void addTopping(String topping) {
9. System.out.println("Cannot and Uoppings");
10. }
11. public static void main(String[] args) {
12. Pizza pizza = new PepperoniPizza();
13. Pizza.addTopping("Mushrooms");
14. } }
What is the result?
A. Cannot and Uoppings B. Compilation fails C. The code runs with no output
D. A NullPointerException is thrown in Line 4 E. None of above.
3|Page
Fayoum University 1st year | Software Engineering 1
Faculty of Engineering Time allowed: 1.5hrs | May 2022
Computer & Systems Eng. Dept. Examiner: Dr. Sayed Taha
Question (2)
A. Given the following numbers 5, 6, 7, -1, 0, 100, 500, -900
Write java class which contains the following methods with full implementation:
* findMax : which returns the maximum number in the array
* findAvg : which returns the average of array content
B. Write the body of the following method which calculates the factoria of any
number:
int calcFac(int number);
condidering that n! = n*(n-1)*(n-2)…..*1 also 0! =1
C. Using the following Die class
Write a method that will use two Die, roll them 100 times, and return the
number of times that total of 7 or 11 is rolled on the two Die.
4|Page