java fundamental

Share Embed Donate


Short Description

java fundamental...

Description

Quiz 1 Sectiunea 4 1. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return to the resources available on this page. True or False? True False (*) 2. Eclipse provides an edit area to help you navigate a hierarchy of information. True or False? True False (*) 3. Eclipse provides views to help you navigate a hierarchy of information. True or False? True (*) False 4. Tabs are used when more than one file is open in the edit area. True or False? True (*) False 5. A perspective is described as: Mark for Review o A combination of views and editors (*) o A combination of views and windows o A combination of editor tabs o None of the above 6. The ______________ is the location onto which you will store and save your files. o Perspective o Workspace (*) o Editor o None of the above 7. A workspace can have one or more stored projects. True or false?

True (*)

False

8. Identify the components in the image below.   A-Main Method, B-Class, CPackage  A-Class, B-MainMethod, CPackage  A-Package, B-Main Method, CClass (*)  None of the above

9. In Eclipse, when you run a Java Application, the results may be displayed in the Console View. True or False? True (*) False

Quiz 2 Sectiunea 4

Sectiunea 4

1

2. When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False? True False (*) 4. A counter used in a For loop cannot be initialized within the For loop statement. True or False? True False (*) 1.Which of the two diagrams below illustrate the general form of a Java program?  Example A  Example B (*)

3. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement? Example A (*) Example B 5. The syntax below represents a valid initialization of a For loop counter. True or False? public class ForLoop { public static void main (String args[]) { for (int i=10; i ,,,,= 5) ? 5 : 10;  numberOfEnemies = ( skillLevel >= 5) ? 10 : 5;  numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*) 20. How would you use the ternary operator to rewrite this if statement? if (gender == "male") System.out.print("Mr."); else System.out.print("Ms.");  System.out.print( (gender == "male") ? "Mr." : "Ms." ); (*)  System.out.print( (gender == "male") ? "Ms." : "Mr." );  (gender == "male") ? "Mr." : "Ms." ;  (gender == "male") ? "Ms." : "Mr." ;

Quiz 3 Sectiunea 6 1. Which of the following would give you an array index out of bounds exception?  Misspelling a variable name somewhere in your code.  Refering to an element of an array that is at an index less than the length of the array minus one.  Using a single equal symbol to compare the value of two integers.  Refering to an element of an array that is at an index greater than the length of that array minus one. (*)  Unintentionally placing a semicolon directly after initializing a for loop. Sectiunea 4

15

2. What exception message indicates that a variable may have been mispelled somewhere in the program?  variableName cannot be resolved to a variable (*)  method methodName(int) is undefined for the type className  Syntax error, insert ";" to complete statement  All of the Above 3. Which of the following defines an Exception?  A very severe non-fixable problem with interpreting and running your code.  Code that has no errors and therefore runs smothly.  A problem that can be corrected or handled by your code. (*)  An interpreter reading your code. 4. What do exceptions indicate in Java?  The code has considered and dealt with all possible cases.  A mistake was made in your code. (*)  There are no errors in your code.  Exceptions do not indicate anything, their only function is to be thrown.  The code was not written to handle all possible conditions. (*) 5. Which line of code shows the correct way to throw an exception?  new throw Exception("Array index is out of bounds");  throw new Exception("Array index is out of bounds"); (*)  throw Exception("Array index is out of bounds");  throws new Exception("Array index is out of bounds"); 6. What does the interpreter look for when an exception is thrown?  It does not look for anything. It just keeps reading through your code.  It does not look for anything. It stops interpreting your code.  The end of the code.  A catch statement in the code. (*) 7. Which of the following would be a correct way to handle an index out of bounds exception?  Throw the exception and catch it. In the catch, set the index to the index of the array closest to the one that was out of bounds. (*)  Do nothing, it will fix itself.  Throw the exception that prints out an error message. There is no need to have the catch handle the exception if it has already been thrown.  Rewrite your code to avoid the exception by not permititng the use of an index that is not inside the array. (*) 8. A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them. The company writes a program to calculate the amount each employee receives, given the number of employees. Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees. What will happen to the program if the company enters 0 into the employment number? Sectiunea 4

16

   

An unfixable error will occur. The program will calculate that each employee will receive zero dollars because there are zero employees. An exception will occur because it is not possible to divide by zero. (*) The programmers will have proven their worth in the company because without them the company wrote faulty code.

Quiz 1 Sectiunea 7 1. Following good programming guidelines, what access modifier should be used for the class fields in the following situation? A car insurance company wants to create a class named Customer that stores all data for a specified customer including the fields: vehicle information, policy information, and a credit card number.  Public  Protected  Private (*)  Default  All of the above 2. A team is working on a coding project. They desire that all portions of their code should have access to the classes that they write. What access modifier should be used for each class?  Public (*)  Protected  Private  Default  All of the above 3. Which of the following could be a reason to need to pass an object into a method?  Easier access to the information contained within the object.  The ability to make changes to an object inside of the method.  Comparing two objects.  All of the above. (*) 4. Which of the following shows the correct way to initialize a method DolphinTalk that takes in 2 integers, dol1 and dol2, and returns the greater int between the two?  int DolphinTalk(dol1, dol2){ if(dol1 > dol2) return dol1; else return dol2;}  int DolphinTalk(int,int){ if(dol1 > dol2) return dol1; else return dol2;}  int DolphinTalk(int dol1,int dol2){ if(dol1 > dol2) return dol1; else return dol2;} (*)  int DolphinTalk, int dol1,int dol2 { if(dol1 > dol2) return dol1; else return dol2;}  All of the above 5. Cameron wishes to write a method that takes in two objects and returns the one with the greatest value. Is this possible?  Yes, but he will have to use two different methods, one to take in the objects and the other to return an object.  Yes, methods can take objects in as parameters and can also return objects all within the same method. (*)  No, it is not possible to return objects. Sectiunea 4

17



No, it is not possible to have objects as parameters or to return objects.

6. You are assigned to write a method that compares two objects of type Career. One requirement of your assignment is to have your method compare the "greatestPossibleSalary" instance data of Career objects. The "greatestPossibleSalary" field is data type int. What would be the best return type from your compare method?  Career, because if it returns the highest paying Career object it will be able to use the same method later to compare other aspects of Career objects. (*)  Integer, because it is the easiest to code with.  String, because is should return a string of the name of the career that is highest paying because none of the other information of the career matters.  Array, because it can store the most information. 7. Consider the following: There is a method A that calls method B. Method B is a variable argument method. With this, which of the following are true?  Method A can invoke method B twice, each time with a different number of arguments. (*)  A compliler error will result since method B does not know how large an array to create when it is invoked by method A.  When invoked, method B creates an array to store some or all of the arguments passed to it from method A. (*)  All of the above. 8. What type(s) would work for a variable argument method? Integers, Strings, and Booleans (*) Constructors Arrays (*) Objects (*) All of the above 9. It is possible to have more than one constructor with the same name in a class, but they must have different parameters. True or false? True (*) False 10. Which of the following is a possible way to overload constructors?

(*) Sectiunea 4

18

Quiz 2 Sectiunea 7 1. Static variables can't use which of the following specifiers?  Public  Protected  Friendly (*)  Default  Private 2. You can assign new values to static variables by prefacing them with the this keyword and a dot or period. True or false? True (*) False 3. Which of the following statements about static methods is true?  They exist once per class. (*)  They exist once in each instance.  They can be overridden by a subclass.  They can access any instance variable.  They cannot access static variables declared outside the method. 4. You can create static class methods inside any Java class. True or false? True (*)

False

5. You can return an instance of a private class through a static method of a different class. True or false? True False (*) 6. You can create static classes as independent classes. True or false? True False (*) 7. You can use an inner static class to return an instance of its outer class container. True or false? True (*) False 8. A linear recursive method can call how many copies of itself?  1 (*)  2 or more  None 9. Which case does a recursive method call last?  Recursive Case  Convergence Case  Basic Case  Base Case (*)  None of the above 10. A non-linear recursive method can call how many copies of itself?  1 Sectiunea 4

19

 

2 or more (*) None

Quiz 3 Sectiunea 7 1. What is a UML?  Unidentified Molding Level, the level of access permitted by the default access specifier.  Unified Modeling Language, a standardized language for modeling systems and structures in programming. (*)  Universal Model Light, a program that reads the brightness of any given lightbulb.  None of the above. 2. What does it mean to inherit a class?  The subclass (or child class) gains access to any non-private methods and variables of the superclass (or parent class). (*)  The access specifier has been set to private.  A way of organizing the hierarchy of classes.  Extending a method from a superclass. 3. Which of the following correctly defines a superclass (or parent class)?  A class that inherits methods and fields from a more general class.  The most specific class of a hierarchy system of classes.  A class that passes down its methods to more specialized classes. (*)  A keyword that allows or restricts access to data and methods. 4. Which of the following correctly defines a subclass (or child class)?  A class that inherits methods and fields from a more general class. (*)  A keyword that allows or restricts access to data and methods.  A class that passes down its methods to more specialized classes.  The most general class of a hierarchy system. 5. Methods are generally declared as public so other classes may use them. True or false? True (*) False 6. Which is the most accurate description of the code reuse philosiphy?  A programming philosophy that promotes stealing your classmates' code.  A programming philosophy that promotes having no concern about the security of code.  A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.  A programming philosophy that promotes simpler, more efficient coding by using existing code for new applications. (*) 7. Which of the following correctly describes the use of the keyword super?  A keyword that restricts access to only inside the same class.  A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)  A keyword that signals the end of a program.  A keyword that allows access from anywhere. 8. Which of the following is the proper way to set the public variable length of the super class equal to 5 from inside the subclass?  super.length() = 5 Sectiunea 4

20

 super.length(5)  super.length = 5 (*)  super(length = 5) 9. What is a hierarchy?  A programming philosophy that promotes simpler, more efficient coding by using existing code for new applications.  A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.  A keyword that allows subclasses to access methods, data, and constructors from their parent class.  A structure that categorizes and organizes relationships among ideas and concepts of things with the most general at the top and the most specific at the bottom. (*) 10. It is possible to extend a class that already exists in Java, such as the Applet class. True or false? True (*) False

Quiz 4 Sectiunea 7 1. Why would a programmer use polymorphism rather than sticking to a standard array?  Because arrays only work using the same object type and polymorphism provides a way around this. (*)  Because it is easier to add or remove objects using polymorphism even when all of the objects are of the same type.  Because arrays are more complex and polymorphism simplifies them by restricting them to only contain the same type objects.  A programmer wouldn't use polymorphism over a standard array. 2. It is possible to override methods such as equals() and toString() in a subclass of Object to fit the needs of the objects of the subclass. True or false? True (*) False 3. Is there a difference between overriding a method and overloading a method?  Yes. Overriding is done within a single class and overloading is done through a series of superclasses and their subclasses.  Yes. Overriding allows for the creation of an array of different object types and overloading restricts an array to only contain the same object types.  Yes. Overriding is done in the subclass and allows for redefining a method inherited from the superclass and overloading is done within a class and allows for multiple methods with the same name. (*)  No, they are the same. 4. Which of the following is a goal of the object model?  Providing modular code that can be reused by other programs or classes. (*)  Concealing implementation. (*)  Data abstraction. (*)  Protecting information and limiting other classes' ability to change or corrupt data. (*) 5. If Sandal extends Shoe, it is possible to declare an object such that Sandal s = new Shoe(); True

False (*)

6. What allows Java to correctly and automatically determine which method to invoke based on the type of object being referred to at the time the method is called? Sectiunea 4

21

   

Abstract classes Polymorphism Inheritance Dynamic Method Dispatch (*)

7. Which of the following are true about an abstract class?  It is possible to create objects of this type.  The Java Virtual Machine does not differentiate abstract classes from concrete classes.  It is possible to create references of this type. (*)  It is identified by the Java keyword abstract. (*)

Sectiunea 4

22

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF