JAVA Revision Lecture Electronic Voting System Marina De Vos.

26
JAVA Revision Lecture Electronic Voting System Marina De Vos

Transcript of JAVA Revision Lecture Electronic Voting System Marina De Vos.

Page 1: JAVA Revision Lecture Electronic Voting System Marina De Vos.

JAVA Revision Lecture

Electronic Voting System

Marina De Vos

Page 2: JAVA Revision Lecture Electronic Voting System Marina De Vos.

0a. What are the languages used in this unit?

1 2 3

0%8%

92%1. C and Java

2. Python and Java

3. Perl and VisualBasic

Page 3: JAVA Revision Lecture Electronic Voting System Marina De Vos.

0b. Ada Lovelace was the first …

1 2 3

48%

39%

13%

1. female programmer

2. the wife of the first programmer

3. programmer

Page 4: JAVA Revision Lecture Electronic Voting System Marina De Vos.

1. Which one of the sentences is true considering the following lines

of code:

1 2 3

71%

13%17%

String country = "England";Town bath = new Town(country);

1. the class Town contains a constructor with a String as a parameter

2. bath is an instance of the class England

3. bath is an object of type String

Page 5: JAVA Revision Lecture Electronic Voting System Marina De Vos.

2. What is the value returned while calling the method refundBalance(10)?

1 2 3 4

4%8%

80%

8%

public int refundBalance(int nb){ balance=100; return balance; balance=0;}

1. 0

2. 10

3. 100

4. Same value as before

Page 6: JAVA Revision Lecture Electronic Voting System Marina De Vos.

3. Which one of the following sentences is correct?

1 2 3 4 5

23%

50%

4%8%

15%

1. Fields represent local variables of a method

2. The scope of a local variable is linked to its defining method

3. Fields are defined inside constructors

4. Local variables are defined in the header of a method

5. A private field can be accessed from outside their

defining class

Page 7: JAVA Revision Lecture Electronic Voting System Marina De Vos.

4. Which values have the variables a and b after the execution of the

following lines of code:

1 2 3 4 5

4%

23%

58%

12%

4%

int a=3;int b=5;int c=a++;int d=--b;if ((a+1)==d){ c++; b--;}if (c!=b){ a++;}else { b++;}

1. a=3; b=4;

2. a=4; b=4;

3. a=3; b=5;

4. a=5; b=4;

5. a=4; b=5;

Page 8: JAVA Revision Lecture Electronic Voting System Marina De Vos.

5. What is the result of n?

1 2 3

24%

44%

32%

boolean pass=false; int n=0; for (int i=0; i<10; i++) { n+=i; if (pass) { i+=2; } pass = !pass; }

1. 27

2. 25

3. 45

Page 9: JAVA Revision Lecture Electronic Voting System Marina De Vos.

6. Why do you need to add 'throws' to a method signature...

1 2 3 4

35%

23%

19%

23%

1. To Specify the exceptions thrown by a method

2. To specify the exceptions caught by a method

3. To Specify that a method overrides an exception

4. Both 1 and 2 are correct Choice One

Page 10: JAVA Revision Lecture Electronic Voting System Marina De Vos.

7. A 'try' must be followed by one or more 'catch' blocks.

1 2

19%

81%

1. True

2. False

Page 11: JAVA Revision Lecture Electronic Voting System Marina De Vos.

8. What happens to the object being created when an exception is thrown from a constructor?

1 2 3 4

62%

4%

27%

8%

1. null is returned and the partial object is garbage collected

2. a partial object is created

3. null is returned4. the object is fully

created

Page 12: JAVA Revision Lecture Electronic Voting System Marina De Vos.

9. Code that is well designed is:

1 2 3 4

12%

62%

15%12%

1. tighly coupled and not cohesive

2. loosly coupled and not cohesive

3. tighly coupled and highly cohesive

4. loosly coupled and highly cohesive

Page 13: JAVA Revision Lecture Electronic Voting System Marina De Vos.

10. Java is a …

1 2 3 4

8%

40%44%

8%

1. weakly and statically typed language

2. weakly and dynamically typed language

3. strongly and statically typed language

4. strongly and dynamically typed language

Page 14: JAVA Revision Lecture Electronic Voting System Marina De Vos.

11. The lifetime and scope of a variable a is defined by the

enclosing {} braces.

1 2

56%

44%

1. True

2. False

Page 15: JAVA Revision Lecture Electronic Voting System Marina De Vos.

12. Object diagrams can present both a static and dynamic view of a

program.

1 2

62%

38%

1. True

2. False

Page 16: JAVA Revision Lecture Electronic Voting System Marina De Vos.

13. To create a new primitive type in Java, you can...

1 2 3 4

8%

19%

12%

62%

1. copy an existing primitive type definition and edit

2. ...you can't!

3. use the new primitive keyword

4. not necessary - all new types are primitive types

Page 17: JAVA Revision Lecture Electronic Voting System Marina De Vos.

14. A & B is the same as B & A for any boolean expression in Java.

1 2

64%

36%

1. True

2. False

Page 18: JAVA Revision Lecture Electronic Voting System Marina De Vos.

15. In Java, it is not possible to have more than one method with

the same name.

1 2

67%

33%

1. True

2. False

Page 19: JAVA Revision Lecture Electronic Voting System Marina De Vos.

16. Consider the following code snippet: What will the output be?

1 2 3 4

8%

40%

32%

20%

HashMap<String,String> map = new HashMap<String,String>(); map.put("key1","arr"); map.put("key1","matey"); System.out.println(map.get("key1"));

1. arr

2. Nothing, it will generate an error.

3. arr matey

4. matey

Page 20: JAVA Revision Lecture Electronic Voting System Marina De Vos.

17. Which of the following statements is incorrect?

1 2 3 4

24%

36%

20%20%

1. the static type of a variable is either the same as the dynamic type or a superclass

2. polymorphic method calls use the dynamic type

3. The compiler checks the static and dynamic type of a variable

4. an object reference can always be type cast back to its dynamic type

Page 21: JAVA Revision Lecture Electronic Voting System Marina De Vos.

18 Newly declared methods can hide, implement, or override methods declared in

a superclass or superinterface.

1 2

36%

64%1. True

2. False

Page 22: JAVA Revision Lecture Electronic Voting System Marina De Vos.

19 It is possible to have a variable with a static type corresponding to an abstract

class

1 2

46%

54%1. True

2. False

Page 23: JAVA Revision Lecture Electronic Voting System Marina De Vos.

20 To simulate multiple inheritance you use:

1 2 3 4

19%

31%

35%

15%

1. nested classes

2. abstract classes

3. interfaces

4. inherited classes

Page 24: JAVA Revision Lecture Electronic Voting System Marina De Vos.

EVS is good fun, something different and its very good to be interactive

Since we do not get much class participation, except if we want to ask questions

1 2 3 4 5

68%

8%12%

0%

12%

1. Strongly Agree

2. Agree

3. Neutral

4. Disagree

5. Strongly Disagree

Page 25: JAVA Revision Lecture Electronic Voting System Marina De Vos.

Java EVS vs Python Quiz

1 2 3 4

44%

4%

24%28%

1. evs

2. Quiz

3. I liked both

4. I liked neither

Page 26: JAVA Revision Lecture Electronic Voting System Marina De Vos.

EVS: Although good for general feed-back how we are doing, it’s not so good for passing course

material on.

1 2 3 4 5

0% 0% 0%0%0%

1. Strongly Agree

2. Agree

3. Neutral

4. Disagree

5. Strongly Disagree