Skip to main content

Web Design and Development MCQs with Answers

Practice important Web Design and Development MCQs with answers and explanations.

Chapter: 3
Q41:
Which class is used to take input from a GUI in Java?
A. Scanner
B. JOptionPane
C. InputStream
D. BufferedReader
Correct Answer: B
Chapter: 3
Q42:
In the InputOutputTest class, what method is used to display a message in a dialog box?
A. showInputDialog
B. showMessageDialog
C. printMessage
D. displayMessage
Correct Answer: B
Chapter: 3
Q43:
What does the parseInt method do in Java?
A. Converts String to int
B. Converts int to String
C. Converts String to double
D. Converts double to int
Correct Answer: A
Chapter: 4
Q44:
Which Java data type is used to store true or false values?
A. int
B. boolean
C. char
D. float
Correct Answer: B
Chapter: 4
Q45:
How do you convert a String to a double in Java?
A. Double.parseDouble(value)
B. Float.parseFloat(value)
C. Integer.parseInt(value)
D. Boolean.parseBoolean(value)
Correct Answer: A
Chapter: 4
Q46:
What does a class in Java represent?
A. A blueprint for objects
B. A method for calculations
C. A type of variable
D. A static method
Correct Answer: A
Chapter: 4
Q47:
What is the purpose of a constructor in Java?
A. To initialize an object
B. To destroy an object
C. To print object data
D. To define static variables
Correct Answer: A
Chapter: 4
Q48:
How are object attributes typically accessed outside the class?
A. Directly
B. Through getters and setters
C. Using public access
D. Through static methods
Correct Answer: B
Chapter: 4
Q49:
What keyword is used to restrict access to a class member only within the same class?
A. protected
B. private
C. public
D. default
Correct Answer: B
Chapter: 4
Q50:
In Java, which method is automatically called to initialize an object?
A. finalize()
B. toString()
C. constructor
D. init()
Correct Answer: C
Chapter: 4
Q51:
What does the finalize() method do in Java?
A. It initializes the object
B. It provides a string representation
C. It is called before an object is destroyed
D. It sets default values for attributes
Correct Answer: C
Chapter: 4
Q52:
How many constructors are provided in the Student class example?
A. One
B. Two
C. Three
D. Four
Correct Answer: C
Chapter: 4
Q53:
Which Java keyword is used to define a method or variable that belongs to the class rather than instances of the class?
A. static
B. final
C. synchronized
D. transient
Correct Answer: A
Chapter: 4
Q54:
What will the getRollNo() method return if a negative roll number is set?
A. The negative roll number
B. Zero
C. 100
D. The original negative number
Correct Answer: C
Chapter: 4
Q55:
How can you ensure a student object is not created with a negative roll number in the Student class?
A. By using the setRollNo() method
B. By using a default constructor
C. By setting rollNo to 0
D. By using the finalize() method
Correct Answer: A
Chapter: 4
Q56:
How are objects of a class created in Java?
A. Using the new keyword
B. Using direct assignment
C. Using static methods
D. Using the create keyword
Correct Answer: A
Chapter: 4
Q57:
Which Java access modifier allows a class member to be accessed by classes in the same package?
A. private
B. protected
C. public
D. default
Correct Answer: D
Chapter: 4
Q58:
What will the Student class’s print() method do?
A. Print the student's name and roll number
B. Return the student's name
C. Initialize the student's attributes
D. Print the number of students
Correct Answer: A
Chapter: 4
Q59:
What is the role of the toString() method in Java?
A. To initialize an object
B. To provide a string representation
C. To compare two objects
D. To print object details
Correct Answer: B
Chapter: 4
Q60:
What happens to an object when System.gc() is called?
A. It forces garbage collection
B. It initializes the object
C. It finalizes the object
D. It creates a new object
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Web Design and Development

🚀 Start Quiz Now