Complete Study Tests
A java application always contains a single method. This method is called...? (Give the signature of this
method) ANS main
public static void main (String[] args)
How is data given to this parameter? ANS Through a command line interface
Ex: java someClass data (args[0] will contain data)
Identifiers can only begin with... ANS Letters, underscores, dollar signs
Which are not key words?
abstract
go
short
boolean
hash
synchronized
continue
instanceof
transient
double
new
try
extends
package
volatile
false
parent
while ANS go, hash, parent
, What does API stand for? ANS Application Programmer Interface
What needs to be done to use the scanner class? ANS import java.util.Scanner;
What is the different between println and print? ANS println ends with a line break
What is encapsulation? ANS The hiding of design decisions in a computer program that are most likely to
change, thus protecting other parts of the program from change is the design is changed. The variables
contained in an object should be modified only within the object.
What are the three visibility modifiers and what is their scope? ANS 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 and by a subclass of its class in another
package
What is the purpose of toString()? ANS To give a human readable representation of the object
What is an accessor method? ANS Defined to access private variable(s) in the class since private data
cannot be accessed from outside the class
What is a mutator method? ANS Defined to modify private variable(s) in the class
What is a constructor? ANS Special method used to create a new object
Define a constructor with two parameters, int x & y, for the class Point ANS public Point(int x, int
y){this.x = x; this.y = y}
Which method signatures would give an error if all methods were defined in a single class?
public int calc(int num1, int num2)
public double calc(int num1, int num2)