ucfstudyunion.files.wordpress.com  · Web viewStudy Union Final Review. Variables/Assignments:...

14
Study Union Final Review Variables/Assignments: 1. Which of the following is the correct way to declare an integer variable named x. a. let x; b. var x; c. x: int d. int x; e. None of the above 2. How many primitive data types are there in Java? Name them. 3. Recall that all the primitive data types have corresponding wrapper classes (i.e. The wrapper class for int is Integer). What is the primitive data type that corresponds with the String class? If there is not one, give a brief explanation how you know this.

Transcript of ucfstudyunion.files.wordpress.com  · Web viewStudy Union Final Review. Variables/Assignments:...

Study Union Final Review

Variables/Assignments:

1. Which of the following is the correct way to declare an integer variable named x.

a. let x;

b. var x;

c. x: int

d. int x;

e. None of the above

2. How many primitive data types are there in Java? Name them.

3. Recall that all the primitive data types have corresponding wrapper classes (i.e. The wrapper class for int is Integer). What is the primitive data type that corresponds with the String class? If there is not one, give a brief explanation how you know this.

4. Consider the following code:

What will be printed to the screen?

5. Consider the following code block:

What is the output? Note: you do not need to provide an exact number. Any reasonable explanation will suffice.

6. Write a line of code that will declare and initialize a new array of type int that has a capacity of 10. Write another line of code that will do the same thing but uses the wrapper class of int instead.

Branches

7. Briefly explain short circuiting and how it differs between “or” statements and “and” statements.

8. In Java, what data type must the expression within an if (…) statement evaluate to? What must that data type evaluate to for the if (…) branch to execute?

9. Consider the following code:

Assume that input was properly declared and initialized as a new Scanner object. If the user enters the number 1, what will the program output?

10. Consider the following code:

Briefly explain the difference between what is being compared in the two if statements.

11. Consider the following code:

Replace the if…else statement with one line of code that will give the same result.

12. Consider the following code:

Replace the if…else if…else statement with a switch statement

Loops

13. Name the three types of loops in Java and describe the structure of each.

14. Explain what the keywords break and continue keywords are used for with respect to loops.

15. Consider the following code:

When will this loop end?

16. Explain how you would print all the elements of a 2D array

17. Consider the following code:

Write a code-block that prints the string one character at a time. You may find the following String method signatures taken from java documentation useful:

Methods

18. Briefly explain method overloading. What must be the same when implementing method overloading? What must be different?

19. Consider the following code:

What is the output? Why?

20. Fill in the blanks to convert the passed array of doubles to an array of ints and return that new array of ints.

Objects/Classes:

21. Explain the difference between a static variable/method versus a non-static variable/method.

22. What classes have access to public class members and methods? What classes have access to private class members and methods?

23. There are 2 main things that distinguish constructors from other methods. What are they?

24. Explain the Java keyword this and what it is used for.

25. What operator is used to access public class members and methods

Inheritance

26. All classes inherit from what class?

27. What makes abstract classes different from other classes?

28. What keyword is used to have a class inherit from another class?

29. Do derived classes have access to all members/methods from the parent class(es)? If not, what specifically does the child class not have access to?

30. Consider the following code:

What will be the output? Why? What concept of Object-Oriented Programming does this use?

Exceptions:

31. To use exceptions, code must be wrapped in what kind of code block?

32. What is the alternative to handling an exception inside a method?

33. When is it required to use exception handling?