Classes, Objects & Methods Flashcards
Class Syntax
class Name {
}
When is a main method required in a class?
If the class is the starting point of you program.
What types of applications don’t require a main method?
Applets
How do you access instance variables from an object?
object.variable
How does the Java compiler sort class definitions?
It puts each class into its own .class file.
Is it necessary for classes to be in the same source file?
No.
Do the contents of the variables in one object differ from another?
Yes, each instance of a class stores its own contents.
Object Declaration Syntax
object Name = new object();
What does the new operator do?
dynamically allocates memory for an object and returns a reference to it.
Reference Variables
Variables referring to objects.
Vehicle car1 = new Vehicle(); Vehicle car2 = car1;
Are car1 and car2 referencing the same or different objects?
Same
What are methods used for?
Manipulating and providing access to data inside classes.
What method begins execution of a program?
The main method
public static void main(String []args)
{
}
Method Syntax
type name(param) {
}
When is the method Return type void?
If the method doesn’t return a value.