Study Solutions
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. For example: java
someCompiledClass data
Identifiers can only begin with? ANS Letters, underscores, dollar sign
Is Java a Functional Language, Procedural Language, Object-Oriented Language, or
Logic Language? ANS Object-Oriented
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's the difference 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 if the design
decision 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 (as with
package-private) and, in addition, by a subclass of its class in another package.
, What is the purpose of toString()? ANS The purpose is to give a readable representation of the object.
What is an accessor method? ANS An accessor method can be defined to access private variable in the
class
since private data cannot be accessed from outside of the class.
What is mutator method? ANS A mutator method can be defined to modify private variable in the class.
What is a constructor? ANS A constructor is a special method that is 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? ANS 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){ ... }
What is the difference between an instance variable, and a local variable? ANS instance variables are
global to all instance methods of the class, local variables are
only visible to the method scope in which its defined.
The this reference refers to the instance of the object. ANS instance