Practice Questions (Conceptual MCQs)

Soft Intro to Java with BlueJ (Objects & Classes)

Table of contents
  1. Easy Level MCQs

    a) Some New Questions for Practice

  2. Medium Level Conceptual MCQs

Easy Level MCQs

  1. What are problem domains in the context of Java programming?
    Specific areas of difficulty in writing Java code
    The subject areas that the program is intended to address
    Specific regions where Java code is executed
    Areas of memory used by Java objects
    Answer

    The subject areas that the program is intended to address

  2. How do Java objects model objects from problem domains?
    By using loops and conditional statements
    By representing real-world entities with classes and objects
    By using arrays and collections
    By utilizing static methods and variables
    Answer

    By representing real-world entities with classes and objects

  3. Which of the following is true about a class in Java?
    It represents a specific instance with its own state
    It is a blueprint from which objects are created
    It is always abstract
    It cannot have methods
    Answer

    It is a blueprint from which objects are created

  4. Which statement correctly differentiates an object from a class?
    A class is an instance of an object
    An object is a blueprint for creating classes
    A class is a general definition, while an object is a specific instance
    An object cannot have methods
    Answer

    A class is a general definition, while an object is a specific instance

  5. What is the naming convention for a class name in Java?
    It should start with a lowercase letter
    It should be in all lowercase letters
    It should start with an uppercase letter
    It should start with a digit
    Answer

    It should start with an uppercase letter

  6. What is another term for ‘calling a method’ in Java?
    Declaring a method
    Overloading a method
    Invoking a method
    Initializing a method
    Answer

    Invoking a method

  7. What is a parameter in the context of a method in Java?
    A variable defined inside the method
    A value that provides additional information to a method
    The name of the method
    The return type of the method
    Answer

    A value that provides additional information to a method

  8. How do you determine what kind of value a parameter accepts in Java?
    By the name of the parameter
    By the data type specified in the method definition
    By the value returned by the method
    By the number of parameters in the method
    Answer

    By the data type specified in the method definition

  9. What is the difference between a method header and a method signature in Java?
    Method header includes the method body; method signature does not
    Method header includes access modifiers; method signature includes parameter types
    Method header is a method call; method signature is a method declaration
    Method header includes return type, name, and parameters; method signature includes name and parameters
    Answer

    Method header includes return type, name, and parameters; method signature includes name and parameters

  10. Which statement is true about the data types int and String in Java?
    Both can store numeric values
    int is a primitive data type, while String is a reference data type
    String can store integers, but int cannot store characters
    Both are reference data types
    Answer

    int is a primitive data type, while String is a reference data type

  11. What happens if a method has no parameters in Java?
    It cannot be called
    It can only return void
    It does not require any arguments when called
    It will cause a compilation error
    Answer

    It does not require any arguments when called

  12. What is the correct format for entering a String value in Java?
    Without any quotes
    Enclosed in single quotes
    Enclosed in double quotes
    Using the keyword String
    Answer

    Enclosed in double quotes

  13. What happens if a String value is entered without quotes for a String parameter in Java?
    It will be treated as an integer
    It will be treated as a variable name
    It will be treated as a boolean
    It will be automatically converted to a String
    Answer

    It will be treated as a variable name

  14. How many objects can be created from a single class in Java?
    One
    Two
    Ten
    Unlimited
    Answer

    Unlimited

  15. Can a method have more than one parameter in Java?
    No, it can only have one parameter
    Yes, it can have multiple parameters separated by commas
    Yes, but they must be of the same data type
    No, it must have exactly one parameter
    Answer

    Yes, it can have multiple parameters separated by commas

  16. What is the state of an object in Java?
    The number of methods it has
    The values of its instance variables at a particular time
    The size of the object in memory
    The type of the object
    Answer

    The values of its instance variables at a particular time

  17. What is the syntax for creating an object of class Rectangle in Java?
    Rectangle obj = new Rectangle();
    Rectangle obj = Rectangle();
    new Rectangle obj = Rectangle();
    Rectangle obj();
    Answer

    Rectangle obj = new Rectangle();

  18. 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?
    No, objects cannot call methods of other objects
    Yes, objects can call methods of other objects of the same class, but not of different classes
    Yes, objects can call methods of other objects of the same or different classes
    No, objects can only call methods of themselves
    Answer

    Yes, objects can call methods of other objects of the same or different classes

  19. What is compilation in Java?
    Running the Java program
    Converting Java source code into bytecode
    Writing the Java code
    Debugging the Java program
    Answer

    Converting Java source code into bytecode

  20. What are field definitions in Java?
    Definitions of methods in a class
    Definitions of local variables inside methods
    Definitions of instance variables in a class
    Definitions of parameters passed to methods
    Answer

    Definitions of instance variables in a class

  21. What is a class in the context of Java programming?
    A blueprint for creating objects.
    An instance of an object.
    A method inside an object.
    A collection of functions.
    Answer

    A blueprint for creating objects.

  22. In the given traffic scenario, if we refer to ‘my old red car parked at home,’ what are we referring to?
    A class
    An object
    A method
    A parameter
    Answer

    An object

  23. What is the naming convention for classes in Java?
    Classes start with lowercase letters.
    Classes start with uppercase letters.
    Classes start with numbers.
    Classes start with special characters.
    Answer

    Classes start with uppercase letters.

  24. Which of the following is an example of a Java object?
    Car
    car1
    int
    public
    Answer

    car1

  25. What does the method signature in Java include?
    Only the method name.
    Only the parameter types.
    The method name and parameter types.
    The return type and parameter values.
    Answer

    The method name and parameter types.

  26. What is an instance in the context of Java programming?
    A class blueprint.
    A specific object created from a class.
    A method definition.
    A parameter value.
    Answer

    A specific object created from a class.

  27. What is the role of parameters in Java methods?
    To define the method's return type.
    To provide additional information for the method.
    To specify the method name.
    To create new objects.
    Answer

    To provide additional information for the method.

  28. How do you start the names of objects in Java?
    With uppercase letters.
    With lowercase letters.
    With special characters.
    With numbers.
    Answer

    With lowercase letters.

  29. What happens when you call the moveDown method twice on a circle object in BlueJ?
    The circle moves twice its original position downward.
    The circle moves back to its original position.
    The circle's size changes.
    The circle becomes invisible.
    Answer

    The circle moves twice its original position downward.

  30. What is the return type of the method getName() in the Student class?
    int
    double
    String
    void
    Answer

    String

  31. Which of the following defines a method that does not take any parameters?
    public void changeSize(int newSize)
    public int getSize()
    public void setSize(int newSize)
    public boolean setVisible(boolean visibility)
    Answer

    public int getSize()

  32. What does invoking the changeColor method on a circle object do?
    It moves the circle.
    It changes the color of the circle.
    It makes the circle invisible.
    It deletes the circle.
    Answer

    It changes the color of the circle.

  33. What is the difference between primitive types and reference types in Java?
    Primitive types store values directly, reference types store references to objects.
    Primitive types store references to objects, reference types store values directly.
    Primitive types are used for objects, reference types for primitive values.
    There is no difference between primitive and reference types.
    Answer

    Primitive types store values directly, reference types store references to objects.

  34. Which of the following is an example of a compile-time error in Java?
    NullPointerException
    ArrayIndexOutOfBoundsException
    Syntax error
    ArithmeticException
    Answer

    Syntax error

  35. What does the method translate(int x, int y) do in the Rectangle class?
    It creates a new rectangle.
    It moves the rectangle by the specified x and y amounts.
    It changes the color of the rectangle.
    It resizes the rectangle.
    Answer

    It moves the rectangle by the specified x and y amounts.

  36. What type of value does the method getCredits() return in the Student class?
    String
    double
    int
    boolean
    Answer

    int

  37. What is a parameter in the context of Java methods?
    A method name.
    A variable passed to a method to provide input.
    The return value of a method.
    An instance of a class.
    Answer

    A variable passed to a method to provide input.

  38. Which method would you use to change the color of a rectangle in Java?
    moveHorizontal
    changeColor
    makeVisible
    setSize
    Answer

    changeColor

  39. How do you create an object with specific RGB values in Java?
    new RGB(255, 0, 0)
    new Color(255, 0, 0)
    new Rectangle(255, 0, 0)
    new Object(255, 0, 0)
    Answer

    new Color(255, 0, 0)

  40. What is the purpose of the main() method in Java?
    To define a class
    To start the execution of a Java application
    To compile the code
    To create new objects
    Answer

    To start the execution of a Java application

  41. What does the method charAt(int index) return in the String class?
    The length of the string
    The character at the specified index
    The substring from the specified index
    The string converted to uppercase
    Answer

    The character at the specified index

  42. Which statement is true about immutability of Strings in Java?
    String values can be changed after creation
    String values cannot be changed once created
    String values are stored in the stack
    String values are always null
    Answer

    String values cannot be changed once created

  43. What is the role of the compiler in Java?
    To execute the code
    To convert source code into machine code
    To create new objects
    To interpret Java bytecode
    Answer

    To convert source code into machine code

  44. What is the result of invoking the method setColor(Color c) on a rectangle object?
    The rectangle moves to a new position
    The rectangle changes its color to the specified color
    The rectangle's size changes
    The rectangle becomes invisible
    Answer

    The rectangle changes its color to the specified color

Back to Top

Some New Questions for Practice

  1. What happens if a class does not have a main() method?
    The program runs successfully
    The class cannot be compiled
    The program will not start
    The class is ignored
    Answer

    The program will not start

  2. What is the return type of the method getHeight() in the Rectangle class?
    void
    int
    double
    boolean
    Answer

    int

  3. What does the method grow(int h, int v) do in the Rectangle class?
    Changes the position of the rectangle
    Changes the size of the rectangle
    Changes the color of the rectangle
    Makes the rectangle invisible
    Answer

    Changes the size of the rectangle

  4. What is the result of calling the setColor(Color.RED) method on a circle object?
    The circle is filled with the color red
    The circle's outline is changed to red
    The circle becomes invisible
    The circle's position is changed
    Answer

    The circle is filled with the color red

  5. What is the purpose of the draw() method in the Circle class?
    To create a new circle
    To fill the circle with color
    To make the circle visible
    To move the circle
    Answer

    To make the circle visible

  6. What does the moveHorizontal method do in the Rectangle class?
    Moves the rectangle horizontally by a specified amount
    Moves the rectangle vertically by a specified amount
    Changes the width of the rectangle
    Changes the height of the rectangle
    Answer

    Moves the rectangle horizontally by a specified amount

  7. Which of the following is a valid declaration of a rectangle object in Java?
    Rectangle rect = new Rectangle();
    Rectangle rect = Rectangle();
    Rectangle rect = new Rectangle;
    rect = new Rectangle();
    Answer

    Rectangle rect = new Rectangle();

  8. What is the purpose of the setSize method in the Rectangle class?
    To change the position of the rectangle
    To change the size of the rectangle
    To change the color of the rectangle
    To make the rectangle visible
    Answer

    To change the size of the rectangle

  9. How do you declare a method that returns an integer in Java?
    public int methodName()
    public void methodName()
    int methodName()
    void methodName()
    Answer

    public int methodName()

  10. Which of the following methods can be used to set the color of a circle object?
    setSize
    setColor
    setVisible
    setPosition
    Answer

    setColor

  11. What is the result of calling the fill() method on a rectangle object?
    The rectangle is moved to a new position
    The rectangle is filled with its current color
    The rectangle is resized
    The rectangle is made invisible
    Answer

    The rectangle is filled with its current color

  12. What is a constructor in Java?
    A method that initializes a new object
    A method that returns an integer
    A method that sets the color of an object
    A method that moves an object
    Answer

    A method that initializes a new object

  13. What does the translate method do in the Line class?
    Changes the color of the line
    Changes the size of the line
    Moves the line by a specified amount
    Deletes the line
    Answer

    Moves the line by a specified amount

  14. Which of the following is a valid way to create a new circle object in Java?
    Circle c = new Circle();
    Circle c = Circle();
    c = new Circle();
    new Circle c = Circle();
    Answer

    Circle c = new Circle();

  15. What is the purpose of the main method in a Java program?
    To start the execution of the program
    To define a class
    To compile the code
    To create new objects
    Answer

    To start the execution of the program

Back to Top

Medium Level Conceptual MCQs

  1. Which of the following statements is true about Java objects modeling objects from problem domains?
    Java objects can only represent physical objects.
    Java objects can represent both physical and abstract objects.
    Java objects cannot represent abstract objects.
    Java objects must always be created using primitive data types.
    Answer

    Java objects can represent both physical and abstract objects.

  2. In a traffic simulation program, how would you categorize “Car”?
    "Car" should always be a class.
    "Car" should always be an object.
    "Car" can be a class, and each specific car is an object.
    "Car" can be an object, and each specific car is a class.
    Answer

    “Car” can be a class, and each specific car is an object.

  3. Which statement correctly describes how objects are created from classes in Java?
    Objects are created using the new keyword and calling the class constructor.
    Objects are created automatically when a class is defined.
    Objects are created using the class keyword.
    Objects are created by declaring them without initialization.
    Answer

    Objects are created using the new keyword and calling the class constructor.

  4. In BlueJ, which of the following is the correct naming convention for a class and an object?
    Class: circle, Object: Circle
    Class: Circle, Object: Circle1
    Class: Circle, Object: circle1
    Class: circle1, Object: Circle
    Answer

    Class: Circle, Object: circle1

  5. Which of the following methods is used to make a circle object visible in BlueJ?
    circle1.show()
    circle1.display()
    circle1.makeVisible()
    circle1.setVisible()
    Answer

    circle1.makeVisible()

  6. Which statement about method parameters in Java is true?
    Methods cannot have parameters.
    Method parameters provide additional information to methods.
    Parameters are not used in method signatures.
    Methods with parameters cannot return values.
    Answer

    Method parameters provide additional information to methods.

  7. What is the correct signature for a method named send that takes a String parameter?
    void send(String message)
    void send(message String)
    send(String message)
    String send(void)
    Answer

    void send(String message)

  8. Which of the following data types is used to store whole numbers in Java?
    String
    int
    boolean
    float
    Answer

    int

  9. What does the state of an object refer to?
    The number of methods the object has.
    The values of the object's properties.
    The class to which the object belongs.
    The name of the object.
    Answer

    The values of the object’s properties.

  10. How do objects in Java interact with each other?
    By changing each other's classes.
    By calling each other's methods.
    By directly modifying each other's private fields.
    By creating new classes.
    Answer

    By calling each other’s methods.

  11. What is the role of a compiler in Java?
    To execute the code line by line.
    To convert source code into machine code.
    To edit the source code.
    To provide runtime environment for code execution.
    Answer

    To convert source code into machine code.

  12. Which statement about return values in Java methods is correct?
    Methods cannot return any values.
    Return values are only used in methods with parameters.
    Return values provide information back to the calling code.
    Methods with return values must always return an int.
    Answer

    Return values provide information back to the calling code.

  13. What does the substring(int beginIndex, int endIndex) method do in Java?
    Returns the character at the specified index.
    Replaces a part of the string.
    Returns a new string that is a substring of the original string.
    Converts the string to uppercase.
    Answer

    Returns a new string that is a substring of the original string.

  14. What type of error is typically caused by dividing a number by zero?
    Syntax error
    Logical error
    ArithmeticException
    NullPointerException
    Answer

    ArithmeticException

  15. Which statement correctly describes the difference between print and println in Java?
    print outputs text without a newline, while println outputs text with a newline.
    print outputs text with a newline, while println outputs text without a newline.
    print can only output integers, while println can output strings.
    There is no difference between print and println.
    Answer

    print outputs text without a newline, while println outputs text with a newline.

Back to Top