Section 5: Java Classes and Objects part 1
What are constructors in Java ?
Constructors are special methods that are invoked when an object is created.
Method overriding is also known as?
Run time polymorphism.
What is a method?
A method is a collection of statements that are grouped together to perform an operation.
What do methods define in Object-Oriented Programming?
Behavior
When you create a static method how will you call that method?
By typing out the class name first and then the method name. Vehicle.horn()
In order to create your own objects in Java what do you have to have?
In java you must have a user defined class that you can instantiate to create an object.
In Java Object-Oriented Programming is a style that is intended to put programmers in the mindset of what?
Real world objects
What is the final key word used for when dealing with variables?
The final keyword is used to make a variable constant. This means that it will be assigned only once.
In java when creating a class the class name and what else has to be the same
The java file which contains the class has to have the same name as the class.
To override a method the method must have?
The overridden method must have the same method signature and parameters.
What is the private access modifier in Java?
The private access modifier in Java will bind the data to the class it resides in. Which means it is only accessible within that class.
What is the protected access modifier used for?
The protected access modifier will allow access within the same package and it will also allow access to the child class if it resides outside the package
What is the public access modifier in Java?
The public access modifier in Java will allow you access to the data anywhere in the program.
What is the return key word used for inside methods?
The return keyword is used to return a value inside a method.
In method overloading the methods must have?
The same name, but different parameters.
How do you create an object in Java?
You can create an object by instantiating a class.
What key word do you use when you want to return a word?
You can use the String key word for the return type in your method signature.
What is another name for method overloading?
compile-time polymorphism
In Object-Oriented programming each object has what three dimensions?
identity, attributes, behavior
In the code below what are the fields and methods? public class Animal { int legs = 2; String name = "John"; public void sound() { System.out.println("Hello"); } }
legs, name, and sound()
A constructor must have the same what as the class it resides in?
name
Can you override a constructor?
no
Can you override a static method?
no
Is Java a fully Object-Oriented Programming language?
no
List the access modifiers in Java?
public, private, protected, default
What is a class in Java?
the user defined blue print with fields and methods.
What are the attributes in a class?
the variables or fields within a class
What key word do you use when you do not want any return?
void
Can you overload a constructor?
yes
Can you overload a static method?
yes
Can you use static and final together?
yes
How many attributes can you define in a class?
you can define as many fields as you want
What happens when you declare a variable or method static in Java?
This means that the variable or method will belong to the class, rather than to a specific instance.
How do you call a method?
To call a method, type its name and then follow the name with a set of parentheses.