Beruflich Dokumente
Kultur Dokumente
Answer all of the following questions, with justification for your answers. Send your answers in the form
of a word or PDF document to my email: amira.abdelaziz@fue.edu.eg .
1- What will appear in the standard output when you run the Tester class?
class Tester {
int var;
Tester(double var) {
this.var = (int)var;
}
Tester(int var) {
this("hello");
}
Tester(String s) {
this();
System.out.println(s);
}
Tester() {
System.out.println("good-bye");
}
public static void main(String[] args) {
Tester t = new Tester(5);
}
}
a) nothing
b) "hello"
c) 5
d) "hello" followed by "good-bye"
e) "good-bye" followed by "hello"
1: class Test
2: {
3: void show()
4: {
5: System.out.println("non-static method in Test");
6: }
7: }
8: public class Q3 extends Test
9: {
10: static void show()
11: {
12: System.out.println("Overridden non-static method in Q3");
13: }
14:
15: public static void main(String[] args)
16: {
17: Q3 a = new Q3();
18: }
19: }
4- If a local variable of a method shop() belonging to a class called Walmart has the same name as
a data member of Walmart, which value is used when shop() is executing?
a) the local variable’s
b) the class variable’s
c) the data member’s
d) None of the above since this would cause a compiler error.
5- Implement class Account as shown in the following diagram. Write down the complete
implementation for all the methods mentioned in the class diagram.
- private member
+ public member
# protected member
Account.java
return balance;
}
Page 1
Shape.java
import java.awt.Point;
import java.awt.Color;
abstract class Shape {
protected Shape() {
Page 1
Circle.java
import java.awt.Point;
import java.awt.Color;
public class Circle extends Shape {
private double radius;
public Circle() {
this.radius = 1;
}
Page 1
Rectangle.java
import java.awt.Point;
import java.awt.Color;
public class Rectangle extends Shape {
public Rectangle() {
this.height = 1;
this.width = 2;
}
Page 1