Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Chapter: 4
Q61:
How does Java handle memory management for objects?
A. Through explicit memory allocation
B. Through garbage collection
C. By manually freeing memory
D. By using pointers
Correct Answer:
B
Chapter: 4
Q62:
What is the result of setting s3.setRollNo(-10); in the Student class example?
A. The roll number will be set to -10
B. The roll number will remain unchanged
C. The roll number will be set to 100
D. The roll number will be set to 0
Correct Answer:
C
Chapter: 5
Q63:
What is a characteristic of static variables in Java?
A. They are shared among all instances of the class
B. They are unique to each instance
C. They can be modified by any object
D. They are not accessible without an object
Correct Answer:
A
Chapter: 5
Q64:
What is the main use of a copy constructor in Java?
A. To initialize an object from another object
B. To destroy an object
C. To print object details
D. To set default values for attributes
Correct Answer:
A
Chapter: 5
Q65:
What is the primary purpose of inheritance in Java?
A. Code reusability
B. Code encapsulation
C. Code optimization
D. Code debugging
Correct Answer:
A
Chapter: 5
Q66:
In Java, which keyword is used to indicate inheritance?
A. extends
B. inherits
C. super
D. this
Correct Answer:
A
Chapter: 5
Q67:
How many classes can a Java class directly inherit from?
A. One
B. Two
C. Multiple
D. None
Correct Answer:
A
Chapter: 5
Q68:
Which Java class is the root of all other classes?
A. Object
B. Employee
C. Teacher
D. Manager
Correct Answer:
A
Chapter: 5
Q69:
What must be the first statement in a subclass constructor if calling a superclass constructor?
A. a method call
B. a return statement
C. a super() call
D. a this() call
Correct Answer:
C
Chapter: 5
Q70:
How does Java handle method overriding in subclasses?
A. All methods are overridden by default
B. Methods need to be explicitly marked
C. Methods are overridden only if the subclass method has the same name and parameters
D. Methods cannot be overridden
Correct Answer:
C
Chapter: 5
Q71:
What will the following code snippet output: System.out.println(new Employee().toString());?
A. Employee class object
B. Employee ID and name
C. ID and name from Employee class
D. Employee ID only
Correct Answer:
C
Chapter: 5
Q72:
How do you explicitly call a superclass method from a subclass in Java?
A. Use super keyword
B. Use this keyword
C. Use extends keyword
D. Use call keyword
Correct Answer:
A
Chapter: 5
Q73:
What is the default access level for members of a class in Java if no access modifier is specified?
A. public
B. private
C. protected
D. package-private
Correct Answer:
D
Chapter: 5
Q74:
What does polymorphism in Java allow?
A. Multiple methods with the same name
B. Different methods with different names
C. The same method with the same name in multiple classes
D. Multiple methods with different names
Correct Answer:
A
Chapter: 5
Q75:
Which keyword is used for up-casting in Java?
A. (int)
B. (double)
C. explicit
D. implicit
Correct Answer:
D
Chapter: 5
Q76:
What does down-casting require in Java?
A. Implicit type conversion
B. Explicit type conversion
C. No type conversion needed
D. Implicit type casting
Correct Answer:
B
Chapter: 5
Q77:
In Java, how do you handle the scenario where a class needs to be converted to a more specific type?
A. Use up-casting
B. Use down-casting
C. Use casting without specifying type
D. Use automatic type conversion
Correct Answer:
B
Chapter: 5
Q78:
What will the following code snippet output: System.out.println(new Teacher().toString());?
A. Teacher object information
B. Teacher qualification only
C. ID and qualification from Teacher class
D. Teacher name and ID only
Correct Answer:
C
Chapter: 5
Q79:
What is the difference between a constructor and a method in Java?
A. Constructors do not return values while methods do
B. Methods do not initialize objects while constructors do
C. Constructors can be overridden while methods cannot
D. Constructors are used for object creation while methods perform actions
Correct Answer:
A
Chapter: 5
Q80:
How does Java's garbage collector handle object finalization?
A. By calling finalize() method
B. By manually freeing memory
C. By using delete keyword
D. By automatically releasing memory
Correct Answer:
A