CSE 205 EXAM 1 UPDATED ACTUAL QUESTIONS AND
CORRECT ANSWERS
Question:
1. A java application always contains a single method, this method is called? Give the signature of this
method.
Answer:
main public static void main(String[] args)
Question:
2. How is data given to this parameter?
Answer:
Through a command line interface. For example: java someCompiledClass data
Question:
3. Identifiers can only begin with?
Answer:
Letters, underscores, dollar sign
Question:
4. Is Java a Functional Language, Procedural Language, Object-Oriented Language, or Logic Language?
Answer:
Object-Oriented
Question:
5. What does API stand for?
Answer:
Application Programmer Interface
Question:
6. What needs to be done to use the scanner class?
Answer:
import java.util.Scanner;
Question:
7. What's the difference between println, and print
Answer:
println ends with a line break
Question:
8. What is Encapsulation?
Answer:
The hiding of design decisions in a computer program that are most likely to change, thus protecting other
parts of the program from change if the design decision is changed. The variables contained in an object
should be modified only within the object
, Question:
9. What are the three visibility modifiers and what is their scope?
Answer:
public: can be accessed from anywhere private: can only be accessed from inside the class protected: the
member can only be accessed within its own package (as with package-private) and, in addition, by a
subclass of its class in another package.
Question:
10. What is the purpose of toString()?
Answer:
The purpose is to give a readable representation of the object.
Question:
11. What is an accessor method?
Answer:
An accessor method can be defined to access private variable in the class since private data cannot be
accessed from outside of the class.
Question:
12. What is mutator method?
Answer:
A mutator method can be defined to modify private variable in the class.
Question:
13. What is a constructor?
Answer:
A constructor is a special method that is used to create a new object.
Question:
14. Define a constructor with two parameters int x, y for the class Point.
Answer:
public Point(int x, int y){ this.x = x; this.y = y;}
Question:
15. Which method signatures would give an error if all methods were defined in a single class?
Answer:
public int calc(int num1, int num2){ ... } public double calc(int num1, int num2){ ...} // differing return
type is not enough, must differ in parameter types and/or //number of parameters public int calc(double
num1, int num2){ ... } public int calc(int num3, int num4){ ... } // differs only in parameter name, must
differ in parameter types and/or //number of parameters public int calc(int num1, int num2, int num3){ ... }
Question:
16. What is the difference between an instance variable, and a local variable?
Answer:
instance variables are global to all instance methods of the class, local variables are only visible to the
method scope in which its defined.
CORRECT ANSWERS
Question:
1. A java application always contains a single method, this method is called? Give the signature of this
method.
Answer:
main public static void main(String[] args)
Question:
2. How is data given to this parameter?
Answer:
Through a command line interface. For example: java someCompiledClass data
Question:
3. Identifiers can only begin with?
Answer:
Letters, underscores, dollar sign
Question:
4. Is Java a Functional Language, Procedural Language, Object-Oriented Language, or Logic Language?
Answer:
Object-Oriented
Question:
5. What does API stand for?
Answer:
Application Programmer Interface
Question:
6. What needs to be done to use the scanner class?
Answer:
import java.util.Scanner;
Question:
7. What's the difference between println, and print
Answer:
println ends with a line break
Question:
8. What is Encapsulation?
Answer:
The hiding of design decisions in a computer program that are most likely to change, thus protecting other
parts of the program from change if the design decision is changed. The variables contained in an object
should be modified only within the object
, Question:
9. What are the three visibility modifiers and what is their scope?
Answer:
public: can be accessed from anywhere private: can only be accessed from inside the class protected: the
member can only be accessed within its own package (as with package-private) and, in addition, by a
subclass of its class in another package.
Question:
10. What is the purpose of toString()?
Answer:
The purpose is to give a readable representation of the object.
Question:
11. What is an accessor method?
Answer:
An accessor method can be defined to access private variable in the class since private data cannot be
accessed from outside of the class.
Question:
12. What is mutator method?
Answer:
A mutator method can be defined to modify private variable in the class.
Question:
13. What is a constructor?
Answer:
A constructor is a special method that is used to create a new object.
Question:
14. Define a constructor with two parameters int x, y for the class Point.
Answer:
public Point(int x, int y){ this.x = x; this.y = y;}
Question:
15. Which method signatures would give an error if all methods were defined in a single class?
Answer:
public int calc(int num1, int num2){ ... } public double calc(int num1, int num2){ ...} // differing return
type is not enough, must differ in parameter types and/or //number of parameters public int calc(double
num1, int num2){ ... } public int calc(int num3, int num4){ ... } // differs only in parameter name, must
differ in parameter types and/or //number of parameters public int calc(int num1, int num2, int num3){ ... }
Question:
16. What is the difference between an instance variable, and a local variable?
Answer:
instance variables are global to all instance methods of the class, local variables are only visible to the
method scope in which its defined.