click below
click below
Normal Size Small Size show me how
CIS 112
This is to help you remember questions
Question | Answer |
---|---|
____________ of the Java Development Kit(JDK) is used to execute a java program from the command prompt? | Java |
A method by the same name as the class name and is used to initialize a new instance is called a | constructor |
A reference variable will have the value of _______ | null |
Given: x = 8 y = 2 z = 10 what is the value of the expression: | 18 |
A static variable ____________ | Has only one value for all instances of a class |
According to standard programming conventions, the name of a method should ________ | Capitalize only the first letter of each word beyond the first and concentrate words without any separators. |
All instance variable declarations MUST _______ | Have a data type |
For a given instance variable, what is the best practice to enable another class to obtain the value of the variable? | Declare the instance variable as private and provide a getter method (e.g.,getName() for instance variable name) |
Which of the following statements about static methods are true? - Static method can be called from non-static methods - Static method can be called using the class name dot | 3 and 4 |
If a method declares a parameter by the same name as an instance variable (member property), then the use of the name(by itself) within the body of the method will refer to the parameter. To reference the instance variable the name must be prefixed with | this. |
In general, all instances' variables should be declared _____ unless there is a good reason to do otherwise | private |
In java, a variable declared as short represents a _____________ | 2 byte 2's compliment integer |
Java has a way of hiding details of a class definition. To hide details(so another class cannot see them), you declare them as ____ | private |
The body of a non-void method must contain a ________ statement at each logical end of the method | return |
The main method used to begin execution of a program must be declared with all the following, EXCEPT | Single parameter-string args |
The new operator is used to create a(n) _______ of a class or array: | Instance |
The parseShort() method of what class is used to convert a String to a short? | Short |
The string class provides all of the following methods. EXCEPT: | sin() |
What is the output of the following code? char c = 'C'; switch (c) { case 'A' : case 'B': System.out.print("Good"); break; case 'C' : | Marginal Not so Good |
What is the result of compiling a java source file: | *.class |
What is the value of the variable c in the statements that follow? String phrase = "Java is fun"; int c = phrase.lastIndexOf(" "); | 7 |
What is the value of the variable word in following execution of the statements? String phrase = "Java programming is fun"; String word = phrase. Substring(5,8); | "pro" |
Class Part { Private int number; Private string desc; Private double price; Private static final double discountStep = .15; public double discount(int quantity) { double discountRate | |
Which is an instance variable (of primitive type) | price |
Which is a local variable? | discountRate |
Which is a reference variable | desc |
What is the data size of discountStep in bytes | 8 |
Which is a parameter | quantity |
Which is a constant | discountStep |
discountStep is not abiding by standard programming conventions. It should be: | DISCOUNT_STEP |
Which of the following is the syntax to declare a Java constant named LINE_FEED? | final char LINE_FEED = '\n'; |
Which of the following operators has the highest precedence | + |
Which of the following statements is false? | Instance variables are declared in the body of a method |
Which operator CAN be used with reference variables | != |
You are creating class Part with instance variables part number, description, and cos. According to standard programming conventions what is a good name for part number(camel type)? | partNumber |
You are creating class rental with attributes toolID, description, and noDaysRented. What data type is best appropriate for noDaysRented? | int |
Describe the difference between a static method an instance method(bonus 7 point): | A static method can not be changed while an instance method can be |
List the eight primitive data types in Java in alphabetically order (bonus 8 points) | String,Integer,Double,Boolean,Long, Short,Char,float |