stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Java methods and oop Flashcards | StudBud
Explore
/
Java methods and oop
Java methods and oop
18 terms
·
StudBud Administration
·
18 plays
Test your knowledge on the basics of Java programming language and object-oriented concepts
Flashcards
18 cards
F
Practice quiz
P
Host live
L
Questions
18
Answers
1
What is an object in Java?
An instance of a class
A data type
A method inside a class
A blueprint for creating a class
2
True or false: If a Java class has no constructor, the compiler provides a default constructor.
False
True
3
Which of the following is an example of an object?
int number = 10;
System.out.println("Hello");
String name;
Scanner input = new Scanner(System.in);
4
What is a mutator method also called?
Getter
Constructor
Overloader
Setter
5
What is true about constructors?
They can be private only
They must return a value
They have the same name as the class
They cannot have parameters
6
How do you define a private instance variable in Java?
private int number;
protected int number;
int private number;
public int number;
7
What happens if no constructor is defined in a class?
Java provides a default constructor
The object remains uninitialized
Compilation error occurs
The class cannot be instantiated
8
What does method overloading mean?
Creating multiple objects in one class
Defining multiple classes in one file
Assigning multiple values to one variable
Using multiple methods with the same name but different parameters
9
True or false: A method inside a class can access private instance variables directly.
True
False
10
What is the correct way to define a method that returns a rectangle's area?
public int getArea() { length * width; }
public void getArea() { return length * width; }
public double getArea() { return length * width; }
private double getArea() { length * width; }
11
What is data hiding in Java?
Restricting direct access to fields
Using global variables
Using public access specifier
Encrypting data
12
True or false: A constructor must always have a return type.
False
True
13
What is an accessor method also called?
Destructor
Setter
Constructor
Getter
14
Which access modifier makes a field accessible only within its class?
protected
public
default
private
15
What is the purpose of a constructor?
To destroy an object
To create an object
To initialize an object
To overload a method
16
What does an object contain?
Only constructors
Only methods
Only fields
Both fields and methods
17
What is a class in Java?
A method that performs calculations
A function that stores data
A variable type
A blueprint for creating objects
18
Which statement correctly creates a Rectangle constructor?
Rectangle r = new Rectangle();
new Rectangle r = Rectangle();
Rectangle r(10, 20);
Rectangle r = new Rectangle(10, 20);