JAVA Revision Lecture Electronic Voting System Marina De Vos 0a. What are the languages used in this unit? 1. C and Java 2. Python and Java 3. Perl and VisualBasic 92% 8% 0% 1 2 3 0b. Ada Lovelace was the first … 1. female programmer 2. the wife of the first programmer 3. programmer 48% 39% 13% 1 2 3 1. Which one of the sentences is true considering the following lines of code: String country = "England"; Town bath = new Town(country); 1. 2. 3. the class Town contains a constructor with a String as a parameter bath is an instance of the class England bath is an object of type String 71% 17% 1 2 13% 3 2. What is the value returned while calling the method refundBalance(10)? public int refundBalance(int nb){ balance=100; return balance; balance=0; } 1. 2. 3. 4. 80% 0 10 100 Same value as before 4% 1 8% 2 8% 3 4 3. Which one of the following sentences is correct? 1. 2. 3. 4. 5. Fields represent local variables of a method The scope of a local variable is linked to its defining method Fields are defined inside constructors Local variables are defined in the header of a method A private field can be accessed from outside their 50% defining class 23% 15% 8% 4% 1 2 3 4 5 4. Which values have the variables a and b after the execution of the following lines of code: 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. 2. 3. 4. 5. a=3; b=4; a=4; b=4; a=3; b=5; a=5; b=4; a=4; b=5; 58% 23% 12% 4% 1 4% 2 3 4 5 5. What is the result of n? boolean pass=false; int n=0; for (int i=0; i<10; i++) { n+=i; if (pass) { i+=2; } pass = !pass; } 44% 32% 24% 1. 27 2. 25 3. 45 1 2 3 6. Why do you need to add 'throws' to a method signature... 1. 2. 3. 4. To Specify the exceptions thrown by a method To specify the exceptions caught by a method To Specify that a method overrides an exception Both 1 and 2 are correct Choice One 35% 23% 23% 19% 1 2 3 4 7. A 'try' must be followed by one or more 'catch' blocks. 1. True 2. False 81% 19% 1 2 8. What happens to the object being created when an exception is thrown from a constructor? 1. null is returned and the partial object is garbage collected 2. a partial object is created 3. null is returned 4. the object is fully created 62% 27% 8% 1 2 4% 3 4 9. Code that is well designed is: 1. tighly coupled and not cohesive 2. loosly coupled and not cohesive 3. tighly coupled and highly cohesive 4. loosly coupled and highly cohesive 62% 12% 1 12% 2 15% 3 4 10. Java is a … 1. 2. 3. 4. weakly and statically typed language weakly and dynamically typed language strongly and statically typed language strongly and dynamically typed language 44% 40% 8% 1 8% 2 3 4 11. The lifetime and scope of a variable a is defined by the enclosing {} braces. 1. True 2. False 56% 44% 1 2 12. Object diagrams can present both a static and dynamic view of a program. 1. True 2. False 62% 38% 1 2 13. To create a new primitive type in Java, you can... 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 62% 19% 12% 8% 1 2 3 4 14. A & B is the same as B & A for any boolean expression in Java. 1. True 2. False 64% 36% 1 2 15. In Java, it is not possible to have more than one method with the same name. 1. True 2. False 67% 33% 1 2 16. Consider the following code snippet: What will the output be? HashMap<String,String> map = new HashMap<String,String>(); map.put("key1","arr"); map.put("key1","matey"); System.out.println(map.get("key1")); 40% 1. 2. 3. 4. arr Nothing, it will generate an error. arr matey matey 32% 20% 8% 1 2 3 4 17. Which of the following statements is incorrect? 1. 2. 3. 4. the static type of a variable is either the same as the dynamic type or a superclass polymorphic method calls use the dynamic type The compiler checks the static and dynamic type of a variable an object reference can always be type cast back to its dynamic type 36% 24% 20% 1 2 20% 3 4 18 Newly declared methods can hide, implement, or override methods declared in a superclass or superinterface. 1. True 2. False 64% 36% 1 2 19 It is possible to have a variable with a static type corresponding to an abstract class 1. True 2. False 54% 46% 1 2 20 To simulate multiple inheritance you use: 1. 2. 3. 4. nested classes abstract classes interfaces inherited classes 35% 31% 19% 15% 1 2 3 4 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. Strongly Agree Agree Neutral Disagree Strongly Disagree 68% 12% 12% 8% 0% 1 2 3 4 5 Java EVS vs Python Quiz 1. 2. 3. 4. evs Quiz I liked both I liked neither 44% 28% 24% 4% 1 2 3 4 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. Strongly Agree Agree Neutral Disagree Strongly Disagree 0% 1 0% 2 0% 3 0% 4 0% 5