Practice Questions (Conceptual MCQs)
Soft Intro to Java with BlueJ (Objects & Classes)
Table of contents
Easy Level MCQs
- What are problem domains in the context of Java programming?
Answer
The subject areas that the program is intended to address
- How do Java objects model objects from problem domains?
Answer
By representing real-world entities with classes and objects
- Which of the following is true about a class in Java?
Answer
It is a blueprint from which objects are created
- Which statement correctly differentiates an object from a class?
Answer
A class is a general definition, while an object is a specific instance
- What is the naming convention for a class name in Java?
Answer
It should start with an uppercase letter
- What is another term for ‘calling a method’ in Java?
Answer
Invoking a method
- What is a parameter in the context of a method in Java?
Answer
A value that provides additional information to a method
- How do you determine what kind of value a parameter accepts in Java?
Answer
By the data type specified in the method definition
- What is the difference between a method header and a method signature in Java?
Answer
Method header includes return type, name, and parameters; method signature includes name and parameters
- Which statement is true about the data types int and String in Java?
Answer
int is a primitive data type, while String is a reference data type
- What happens if a method has no parameters in Java?
Answer
It does not require any arguments when called
- What is the correct format for entering a String value in Java?
Answer
Enclosed in double quotes
- What happens if a String value is entered without quotes for a String parameter in Java?
Answer
It will be treated as a variable name
- How many objects can be created from a single class in Java?
Answer
Unlimited
- Can a method have more than one parameter in Java?
Answer
Yes, it can have multiple parameters separated by commas
- What is the state of an object in Java?
Answer
The values of its instance variables at a particular time
- What is the syntax for creating an object of class Rectangle in Java?
Answer
Rectangle obj = new Rectangle();
- Can an object call methods of other objects of the same class in Java? What about an object of one class calling a method of an object of another class?
Answer
Yes, objects can call methods of other objects of the same or different classes
- What is compilation in Java?
Answer
Converting Java source code into bytecode
- What are field definitions in Java?
Answer
Definitions of instance variables in a class
- What is a class in the context of Java programming?
Answer
A blueprint for creating objects.
- In the given traffic scenario, if we refer to ‘my old red car parked at home,’ what are we referring to?
Answer
An object
- What is the naming convention for classes in Java?
Answer
Classes start with uppercase letters.
- Which of the following is an example of a Java object?
Answer
car1
- What does the method signature in Java include?
Answer
The method name and parameter types.
- What is an instance in the context of Java programming?
Answer
A specific object created from a class.
- What is the role of parameters in Java methods?
Answer
To provide additional information for the method.
- How do you start the names of objects in Java?
Answer
With lowercase letters.
- What happens when you call the moveDown method twice on a circle object in BlueJ?
Answer
The circle moves twice its original position downward.
- What is the return type of the method getName() in the Student class?
Answer
String
- Which of the following defines a method that does not take any parameters?
Answer
public int getSize()
- What does invoking the changeColor method on a circle object do?
Answer
It changes the color of the circle.
- What is the difference between primitive types and reference types in Java?
Answer
Primitive types store values directly, reference types store references to objects.
- Which of the following is an example of a compile-time error in Java?
Answer
Syntax error
- What does the method translate(int x, int y) do in the Rectangle class?
Answer
It moves the rectangle by the specified x and y amounts.
- What type of value does the method getCredits() return in the Student class?
Answer
int
- What is a parameter in the context of Java methods?
Answer
A variable passed to a method to provide input.
- Which method would you use to change the color of a rectangle in Java?
Answer
changeColor
- How do you create an object with specific RGB values in Java?
Answer
new Color(255, 0, 0)
- What is the purpose of the main() method in Java?
Answer
To start the execution of a Java application
- What does the method charAt(int index) return in the String class?
Answer
The character at the specified index
- Which statement is true about immutability of Strings in Java?
Answer
String values cannot be changed once created
- What is the role of the compiler in Java?
Answer
To convert source code into machine code
- What is the result of invoking the method setColor(Color c) on a rectangle object?
Answer
The rectangle changes its color to the specified color
Some New Questions for Practice
- What happens if a class does not have a main() method?
Answer
The program will not start
- What is the return type of the method getHeight() in the Rectangle class?
Answer
int
- What does the method grow(int h, int v) do in the Rectangle class?
Answer
Changes the size of the rectangle
- What is the result of calling the setColor(Color.RED) method on a circle object?
Answer
The circle is filled with the color red
- What is the purpose of the draw() method in the Circle class?
Answer
To make the circle visible
- What does the moveHorizontal method do in the Rectangle class?
Answer
Moves the rectangle horizontally by a specified amount
- Which of the following is a valid declaration of a rectangle object in Java?
Answer
Rectangle rect = new Rectangle();
- What is the purpose of the setSize method in the Rectangle class?
Answer
To change the size of the rectangle
- How do you declare a method that returns an integer in Java?
Answer
public int methodName()
- Which of the following methods can be used to set the color of a circle object?
Answer
setColor
- What is the result of calling the fill() method on a rectangle object?
Answer
The rectangle is filled with its current color
- What is a constructor in Java?
Answer
A method that initializes a new object
- What does the translate method do in the Line class?
Answer
Moves the line by a specified amount
- Which of the following is a valid way to create a new circle object in Java?
Answer
Circle c = new Circle();
- What is the purpose of the main method in a Java program?
Answer
To start the execution of the program
Medium Level Conceptual MCQs
- Which of the following statements is true about Java objects modeling objects from problem domains?
Answer
Java objects can represent both physical and abstract objects.
- In a traffic simulation program, how would you categorize “Car”?
Answer
“Car” can be a class, and each specific car is an object.
- Which statement correctly describes how objects are created from classes in Java?
Answer
Objects are created using the new keyword and calling the class constructor.
- In BlueJ, which of the following is the correct naming convention for a class and an object?
Answer
Class: Circle, Object: circle1
- Which of the following methods is used to make a circle object visible in BlueJ?
Answer
circle1.makeVisible()
- Which statement about method parameters in Java is true?
Answer
Method parameters provide additional information to methods.
- What is the correct signature for a method named send that takes a String parameter?
Answer
void send(String message)
- Which of the following data types is used to store whole numbers in Java?
Answer
int
- What does the state of an object refer to?
Answer
The values of the object’s properties.
- How do objects in Java interact with each other?
Answer
By calling each other’s methods.
- What is the role of a compiler in Java?
Answer
To convert source code into machine code.
- Which statement about return values in Java methods is correct?
Answer
Return values provide information back to the calling code.
- What does the substring(int beginIndex, int endIndex) method do in Java?
Answer
Returns a new string that is a substring of the original string.
- What type of error is typically caused by dividing a number by zero?
Answer
ArithmeticException
- Which statement correctly describes the difference between print and println in Java?
Answer
print outputs text without a newline, while println outputs text with a newline.