• Aucun résultat trouvé

LP24: Object Oriented Programing – Final Exam 2h Documents, Computer, Calculator unauthorized

N/A
N/A
Protected

Academic year: 2022

Partager "LP24: Object Oriented Programing – Final Exam 2h Documents, Computer, Calculator unauthorized"

Copied!
3
0
0

Texte intégral

(1)

LP24: Object Oriented Programing – Final Exam 2h

Documents, Computer, Calculator unauthorized

1. Theoretical questions (6 pts)

Question 1: Is it possible to instanciate an interface? An abstract class?

Question 2: Is it possible to put an empty Constructor inside an interface? Inside an abstract class? Can this constructor have a body in both cases?

Question 3: Is the following statement allowed : A a = new B();

If A is an abstract class, derived by the class B? If A is an interface, implemented by the class B?

Question 4: Can an interface/an abstract class contain attributes? With which modifiers?

Question 5: Can an interface inherits from another interface? From an abstract class?

Question 6: Can an abstract class inherit from another abstract class? From an interface?

2. Geometric shapes and code factorization (10 pts)

In this exercise, we aim to manipulate geometric shapes according to the following interface:

interface Geometricable { double perimeter();

double surface();

}

Question 1: Write the classes Circle, Triangle, Rectangle and Square using this interface.

Question 2: A polygon is defined as a set of connected segments (made each of two points) which are not cutting each other (in this exercise it is not asked to check if the lines are cutting each other) and which is starting and finishing at the same point of the space. What is the type of Polygon (abstract class or interface)? What is its relationship with the other classes?

Question 3: modify the previous classes so as to integrate Polygon into this new scheme. You may need to introduce new “tool” classes.

(2)

Question 4: A polygon is convex if all segments that link any couple of points of the periphery are included into the shape of the polygon. If a polygon is convex, its surface is given by the following equation:

With (xi,yi) the ordered set of points of the polygon. (see next figure)

What can be the type of ConvexPolygon and what are the relationships with the other classes/interfaces? Write the corresponding code.

(3)

3. What is the output of the following program (4 pts)

Here is a program:

class Less {

public int n ;

public Less(int x) { n = x ; }

public String toString() { return "Less ! " ; } public void test1() {

System.out.println("Less.test1 : " + this.toString());

}

public void test2() {

System.out.println("Less.test2 : " + this.n);

} }

class More extends Less{

public int n ;

public More(int x, int y) { super(x) ; this.n = y ; } public String toString() { return "More ! " ; } public void test1() {

super.test1() ; System.out.println(

"More.test1 : " + this.toString() + super.toString());

}

public void test2() { super.test2() ;

System.out.println( "More.test2 : " + this.n + super.n);

}

public static void main(String argv[]) { More m = new More(1, 2) ; m.test1() ;

m.test2() ;

Less n = new Less(0) ; n.test1() ;

n.test2() ; }

}

What is the output on the screen?

Références

Documents relatifs

The goal of the exercise is to write the required classes which embedded the methods aimed at writing the following patterns on the screen!. Try to do so with as

The goal of the exercise is to write the required classes which embedded the methods aimed at writing the following patterns on the screen.. Try to do so with as

A droid can be from one or several types, each of them being associated to a set of possible actions such as firing for droid from type #4 or repairing ships for droid from type

The goal of this exercice is to program the missing classes so as to make this code working properly.. Considering the StarWars.java file provided, the compiler will make

Even if you don’t know a lot about ruby, you should still be able to write a metasploit exploit module based on this tutorial and the existing exploits available in

Without any further considerations it is possible to check (actually, prove) that the investigated curve is a parabola also in the symbolic sense.. To achieve this re- sult one

Suppose R is a right noetherian, left P-injective, and left min-CS ring such that every nonzero complement left ideal is not small (or not singular).. Then R

Whereas in [2] a main ingredient was a construction by Wermer [4] of a non-Runge polydisk in C 3 we will use the construction of a non-Runge Fatou–Bieberbach domain in C 2 , [6]..