0% found this document useful (0 votes)
49 views4 pages

My Fault Book 687

The document is an examination paper for first-year Software Engineering students at Fayoum University, dated May 2022. It includes multiple programming questions that test knowledge of Java, covering topics such as arrays, inheritance, interfaces, and method implementations. Students are required to analyze code snippets and provide expected outputs or implement specific methods based on given requirements.

Uploaded by

mostfa8mahmod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views4 pages

My Fault Book 687

The document is an examination paper for first-year Software Engineering students at Fayoum University, dated May 2022. It includes multiple programming questions that test knowledge of Java, covering topics such as arrays, inheritance, interfaces, and method implementations. Students are required to analyze code snippets and provide expected outputs or implement specific methods based on given requirements.

Uploaded by

mostfa8mahmod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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 (1)

1. Given the following code:

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. } }

What is the result?

A. Prints: 0,0,0,null B. Prints: 0,0,0.0,null

C. Prints: 0,0,0,0 D. Prints: null,null,null,null

E. The code runs with no output.

2. Given the following code:

1. public class SimpleCalc {


2. public int value;
3. public void calculate( ) { value += 7; }
4. }
And:
5. public class MultiCalc extends SimpleCalc {
6. public void calculate( ) { value += 3; }
7. public void calculate( int multipier) {
8. calculate( );
9. super.calculate( );
10. value *= multipier;
11. }
12. public static void main(String[] args) {

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

13. MultiCalc calculator = new MultiCalc( );


14. calculator.calculate(2);
15. System.out.println(“ Value is: “ + calculator.value);
16. } }
What is the result?
A. Value is: 8 B. Compilation fails.
C. Value is: 20 D. Value is: -20
E. The code runs with no output.

3. Given the following code:

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.

4. Given the following code:

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 Animal { public String noise () { return “peep”} }


2. class Dog extends Animal {
3. public String noise () { return “back”; }
4. }
5. class Cat extends Animal {
6. public String noise () { return “move”; }
7. }
8. . . . //skip parts of code
9. Animal animal = new Dog();
10. Cat cat = ( Cat ) animal;
11. System.out.printIn( cat.noise() ) ;
What is the result?
A. peep B. back C. move
D. Compilation fails. E. An exception is thrown at runtime

5. Given the following code:

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

You might also like