Skip to main content

Important Web Design and Development Short Questions

Chapter: 5
Question 1:
What is type casting in Java?
Answer: Type casting in Java is the process of converting a variable from one data type to another. It can be implicit (up-casting) or explicit (down-casting), depending on the conversion direction between data types or class types.
Chapter: 5
Question 2:
What is up-casting in Java, and when is it used?
Answer: Up-casting in Java is the implicit conversion of a subclass reference to a superclass reference. It is used when a method expects an object of the superclass but an object of the subclass is passed instead.
Chapter: 5
Question 3:
What is down-casting in Java, and what are its risks?
Answer: Down-casting in Java is the explicit conversion of a superclass reference back to a subclass reference. It can be risky as it may lead to ClassCastException if the object being cast is not actually an instance of the subclass.
Chapter: 5
Question 4:
What is the role of constructors in inheritance?
Answer: In Java inheritance, constructors of a subclass can call a superclass constructor using the super keyword. This ensures that the base class is properly initialized before the subclass adds its own initializations.
Chapter: 5
Question 5:
How does method overriding work in Java?
Answer: Method overriding in Java occurs when a subclass provides its own implementation of a method that is already defined in its superclass. The subclass method should have the same name, return type, and parameters.
Chapter: 5
Question 6:
Why are all Java methods virtual by default?
Answer: In Java, all methods are virtual by default, meaning they can be overridden by subclasses unless they are declared as final. This allows Java to support dynamic method binding for polymorphism.
Chapter: 6
Question 7:
What does a collection represent in Java?
Answer: A collection represents a group of objects known as its elements.
Chapter: 6
Question 8:
What is an advantage of using a collection over an array in Java?
Answer: You don’t need to know the eventual size of the collection in order to add objects to it.
Chapter: 6
Question 9:
Which package in Java provides collection classes?
Answer: The java.util package provides a set of collection classes.
Chapter: 6
Question 10:
What are some common methods provided by Java collection classes?
Answer: Common methods include get(), size(), and isEmpty().