• Aucun résultat trouvé

LP24 Object Oriented Programing Final Exam - Spring 2014 !! ! ! ! ! ! ! ! ! !! ! ! ! ! ! ! ! ! !

N/A
N/A
Protected

Academic year: 2022

Partager "LP24 Object Oriented Programing Final Exam - Spring 2014 !! ! ! ! ! ! ! ! ! !! ! ! ! ! ! ! ! ! !"

Copied!
2
0
0

Texte intégral

(1)

LP24 Object Oriented Programing!

Final Exam - Spring 2014!

! Documents, Computer, Calculator unauthorized !

! !

1. Theoretical questions (4 pts)!

! A. What means inheritance between two classes? What is multiple inheritance? Is this possible in Java?

! B. What is the purpose of interfaces? How to write a class which implements an interface in java?

How many interfaces a class can implement?

! C. Which binding is used by default in Java? How it is made when one use static methods?

!

2. Exercise #1: (4 pts)!

! Gives the result written by this program on screen . Corrects possible mistakes.

! class  AbstractStatic  {    

public  static  void  main(String[]  args)  {     N  n1  =  new  N()  ;    

N  n2  =  new  N(4)  ;     N  n2  =  new  N(3)  ;     C  c1=  new  C()  ;   n1.m1(2)  ;     n2.m1(true)  ;    

! System.out.println(c1.n)  ;     System.out.println(n1.n)  ;     System.out.println(n1.i)  ;     System.out.println(n2.n)  ;   System.out.println(n2.i)  ;     }  

}    

! abstract  class  C  {    

  private  int  n  =  0  ;       C()  {    

  n++  ;  }  

!! class  N  extends  C{    

  private  int  i  =  1  ;       private  boolean  b=  true  ;  

!

N(int  j)  {    

  this.i=i+2  ;     this.n=i+5  ;   }    

! N(int  i)  {    

  this.i=i+3  ;     this.n=  i+6  ;   }    

! N(boolean  b)  {       this.b=  b  ;     i++  ;     }    

! void  m1(int  j)  {       i++  ;   }    

! void  m1(boolean  bool)  {       if(bool)  

    {  

    i++  ;    

    }  

 }   }


3. Exercise #2 (4 pts):!

Writes the following classes:

•! Person:

•! Abstract class.

•! Attributes : name, surname : string.

(2)

•! Default constructor.

•! Constructor with two parameters.

•! Student :

•! Inherits from the Person class.

•! Implements an interface StudentInterface.

•! Attributes : ine : string.

•! Default constructor using the constructor of the class Person.

•! Constructor with 3 parameters (name, ine) using the constructor of the class Person.

!

4. Exercise #3: Fun with # (8 pts)!

! 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 few methods as possible. (One method for each pattern is not the correct answer). Each pattern must have parameters for specifying the size of each pattern and must be stored in memory using a collection of your choice.

Some of these patterns are composed several patterns, try to think in terms of composition of patterns while defining a new one. (Tips: one can try to define operations between patterns) !

!

#                                        #  #  #  #  #  #  #  #            #  #  #  #  #  #  #  #                                        #  

#  #                                    #  #  #  #  #  #  #                    #  #  #  #  #  #  #                                    #  #  

#  #  #                                #  #  #  #  #  #                            #  #  #  #  #  #                                #  #  #  

#  #  #  #                            #  #  #  #  #                                    #  #  #  #  #                            #  #  #  #  

#  #  #  #  #                        #  #  #  #                                            #  #  #  #                        #  #  #  #  #  

#  #  #  #  #  #                    #  #  #                                                    #  #  #                    #  #  #  #  #  #  

#  #  #  #  #  #  #                #  #                                                            #  #                #  #  #  #  #  #  #  

#  #  #  #  #  #  #  #            #                                                                    #            #  #  #  #  #  #  #  #            (a)                                      (b)                                    (c)                                    (d)  

!!

#  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #  

#                      #            #                                                #                #              #            #  #              #  #  

#                      #                #                                        #                        #      #                #      #      #      #  

#                      #                    #                                #                                #                    #          #          #  

#                      #                        #                        #                                #      #                #      #      #      #  

#                      #                            #                #                                #              #            #  #              #  #  

#  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #        #  #  #  #  #  #  #            (e)                              (f)                          (g)                            (h)                            (i)  

!

#  #  #  #  #  #  #  #  #  #  #                                #                                                    #      #  #  #  #  #  #  #  #  #                                #  #  #                                            #  #  #          #  #  #  #  #  #  #                                #  #  #  #  #                                    #  #  #  #  #              #  #  #  #  #                                #  #  #  #  #  #  #                            #  #  #  #  #  #  #                  #  #  #                                #  #  #  #  #  #  #  #  #                    #  #  #  #  #  #  #  #  #                      #                                #  #  #  #  #  #  #  #  #  #  #            #  #  #  #  #  #  #  #  #  #  #                    (j)                                                (k)                                  #  #  #  #  #  #  #  #  #                                                                                                                      #  #  #  #  #  #  #                                                                                                                          #  #  #  #  #                                                                                                                              #  #  #                                                                                                                                  #                                                                                                                        (l)  

!!

A. Write the class diagram that corresponds to your proposal. Don’t forget to include the class corresponding to the collection you choose.!

! B. Write the content of the classes you defined in the previous question!

! C. If I want to change the type of the collection, which are the parts that I have to modify?!

Références

Documents relatifs

To support Member States in addressing this challenge, on 26 April 2018, the Commission adopted an ambitious proposal for a Council Recommendation and a Communication that aim

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

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

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

Finally, the ratio λ max /λ min being called the condition number of the matrix A, state a condition that garanties a small instability in the resolution of a linear

Exercises for the preparation to the final

2 What six things do you think would be the most useful things to have in the jungle?. Make a list, and say why each thing