Skip to main content

Important Web Design and Development Short Questions

Chapter: 4
Question 1:
What is the difference between public and private access modifiers?
Answer: Public members are accessible anywhere, while private members are only accessible within the class they are defined in.
Chapter: 4
Question 2:
What is a static variable or method in Java?
Answer: Static variables or methods belong to the class rather than any specific object, meaning they are shared among all instances of the class.
Chapter: 4
Question 3:
What is the finalize() method in Java?
Answer: The finalize() method is called by the garbage collector before an object is destroyed, allowing the object to perform cleanup tasks like closing files.
Chapter: 4
Question 4:
What is the purpose of the toString() method in Java?
Answer: The toString() method is used to convert an object’s state into a string representation. It's commonly overridden to provide a meaningful string output.
Chapter: 5
Question 5:
What is inheritance in Java?
Answer: Inheritance in Java is a mechanism where one class acquires the properties (fields and methods) of another class, promoting code reuse. The parent class is called the superclass, and the child class is the subclass.
Chapter: 5
Question 6:
How does Java support inheritance compared to C++?
Answer: Unlike C++, Java only supports single inheritance, meaning a class can only inherit from one other class at a time. Java uses the extends keyword for inheritance, and all functions are virtual by default.
Chapter: 5
Question 7:
What is the significance of the super keyword in Java?
Answer: The super keyword in Java is used to refer to the immediate parent class object. It is used to call superclass constructors and methods. The call to the superclass constructor must be the first line in a subclass constructor.
Chapter: 5
Question 8:
What is the default superclass in Java?
Answer: In Java, every class implicitly inherits from the Object class, which is the root class of the Java class hierarchy. This means all Java classes inherit methods from the Object class unless explicitly defined otherwise.
Chapter: 5
Question 9:
What is polymorphism in Java?
Answer: Polymorphism in Java allows objects of different classes to be treated as objects of a common superclass. The actual method that gets called is determined at runtime, enabling dynamic method binding or late binding.
Chapter: 5
Question 10:
How does Java achieve polymorphism?
Answer: Java achieves polymorphism through method overriding, where a subclass provides a specific implementation of a method already defined in its superclass. This allows a parent class reference to call subclass methods.