1 / 32

Review

Review. 1. How many primitive data types in Java?. 6 8 10 12. 2, After execution of the code fragment below, what are the values of the variables result, a, and b? int result, a=10,b=11; result=( a++ + b--)%5;. result= 3, a = 11, b = 10 result= 2, a = 10, b = 11

cardea
Download Presentation

Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review

  2. 1. How many primitive data types in Java? • 6 • 8 • 10 • 12

  3. 2, After execution of the code fragment below, what are the values of the variables result, a, and b? int result, a=10,b=11;result=( a++ + b--)%5; • result= 3, a = 11, b = 10 • result= 2, a = 10, b = 11 • result= 1, a = 11, b = 10 • result= 1, a = 11, b = 11

  4. 3. After execution of the code fragment below, what are the values of the variables result, a, and b? int result, a=10,b=11; result = ((++a) > b) ? a : b; • result= 11, a = 11, b = 11 • result= 0, a = 11, b = 11 • result= 10, a = 11, b = 11 • result= 11, a = 10, b = 11

  5. 4. A statement for a constructor that invokes the no-args, default constructor in its superclass is: • this.constructor(); • descendent classes can not call constructors of their superclass. • This • super();

  6. The program has a syntax error because Test does not have a default constructor. • The program has a syntax error because x has not been initialized. • The program has a syntax error because you cannot create an object from the class that defines the object. • The program has a syntax error because System.out.println method cannot be invoked from the constructor.

  7. 6. Assume class A extends class B, that is, class A is defined as: class A extends B { .... }// end of class A Which class is the super class and which one is the subclass? • B is both the super class and subclass • B is the super class, A is the subclass • A is both the super class and subclass • A is the super class, B is the subclass

  8. 7. Choose the 1 item below that is not typically listed as a major component of object oriented languages: • Polymorphism • Inheritance • Abstraction • Encapsulation

  9. 8. Choose the best answer. What is created by lines 6-9 of the Point3D subclass? 3: public class Point3D extends Point { 4: public int z; 5: 6: public Point3D(int x, int y, int z) { 7: super(x,y); 8: this.z = z; 9: } • constructor method • method to extend Point3D • new method called Point3D

  10. 9. What does the following code do? double a=Double.parseDouble(new String ("12.566")); • Converts the double 12.566 into a string with the text 12.566 • Syntax Error • Converts a string with the text 12.566 into an double with the value 12 • Converts a string with the text 12.566 into an double with the value 12.566

  11. 10. What is about constructor? • it has the same name as the class • it does not return a value • it has void • it often sets the initial values of instance variables

  12. 11. What is about overloading? • Method overloading is the process of using the same method name for multiple methods • The signature of each overloaded method must be unique  • The signature includes the number, type, and order of the parameters • Constructors can not be overloaded

  13. 12. Assume s = " aa bb ccdd efg kh "; What's the value of count after this while loop? int count=0;StringTokenizer tokenizer = new StringTokenizer (s); while (tokenizer.hasMoreTokens()) { count++; tokenizer.nextToken(); } • 5 • 6 • 7 • 8

  14. 13. What is about Static modifier? • Static variables are sometimes called class variables • The static modifier can be applied to variables as well • Static methods cannot reference instance variables, because instance variables don't exist until an object exists • The static modifier can not be applied to variables

  15. 14. What is about Overriding? • Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature • Overriding deals with two methods, one in a parent class and one in a child class, that have the diferrent signature • Overriding l deals with two methods in the same Class • Overriding lets you define a similar operation in different ways for different object types

  16. 15. Which correctly creates an array of five empty Strings? • String[] a = new String [5]; • String[] a = {"", "", "", "", ""}; • String[5] a; • String[ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null;

  17. 16. which of the following are valid identifiers? • _id • $id • #id • -id

  18. 17. which of the following are characteristic of a fully encapsulated class? • all variables are private • all methods are private • methods are provided to access the class's properties • the class's design may be changed with minimal impact on its implementation

  19. 18. Which of these are valid declaration of the main() method? • public void main(String args[]) {/* … */} • static void main(String args[]) {/* … */} • public static int main(String args[]) {/* … */} • final static public void main(String[] arguments) {/* … */}

  20. 19. which of the following is not a wrapper class? • String • Integer • Boolean • character

  21. 20. Which three are valid declarations of a float? (Choose three.) • float foo = -1; • float foo = 1.0; • float foo = 42el; • float foo = 2.02f; • float foo = 3.03d; • float foo = 0x0123;

  22. 21. Which two are legal String declarations? (Choose two.) • String s = null; • String s = 'null'; • String s = (String)'abc'; • String s = "This is a string";

  23. 22. Which two are valid declarations of a float? (Choose two.) • float f = 1F; • float f = 1.0; • float f = '1'; • float f = "1"; • float f = 1.0d;

  24. 23. Which two are valid declarations of a boolean? (Choose two.) • boolean b = 0; • boolean b = true; • boolean b = "true"; • boolean b = 'true'; • boolean b = (3 >= 0); • boolean b = Boolean.TRUE;

  25. 24. Given:11. Object objA = new Object();12. Object objB = new Object();13. Object objC = objA;Which two evaluate to true? (Choose two.) • objA == objB • objC == objA • objB == objC • objA.equals(objC) • objB.equals(objA)

  26. 25. Given:11. String s = "Hello" + 9 + 1;12 System.out.println(s);What is the result? • Hello91 • Hello10 • Compilation fails. • An exception is thrown at runtime.

  27. 26. Given:21. int i = 1;22. int j = i++;23. if((i == ++j) | (i++ == j)) {24. i += j;25. }26. System.out.println("i = " + i);What is the result? • i = 1 • i = 2 • i = 3 • i = 4 • i = 5

  28. 27. Given:11. int i = 0, j = 1;12. if((i++ == 0) || (j++ == 2)) {13. i = 42;14. }15. System.out.println("i = " + i + ", j = " + j);What is the result? • i = 1, j = 2 • i = 1, j = 1 • i = 42, j = 2 • i = 42, j = 1

  29. 28. Which two demonstrate encapsulation of data? (Choose two.) • Methods are protected. • Instance variables are private. • Instance variables have default access. • Instance variables can be modified directly. • Instance variables are accessed and modified only through methods.

  30. 29. Given "B is a D" and "B has a C," which two statements are true? (Choose two.) • D refers to C. • B refers to C. • D inherits from B. • B inherits from D

  31. 30. Which modifier, when applied to instance variable, breaks encapsulation? • void • final • public • static • private

  32. Finish

More Related