What relationship does extends establish in Java?
A superclass is a general class; a subclass is a specialized class that extends it with extends. For example, Car extends Vehicle.
Study Java Inheritance and Polymorphism with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What relationship does extends establish in Java?
A superclass is a general class; a subclass is a specialized class that extends it with extends. For example, Car extends Vehicle.
How many direct superclasses can a Java class have?
Java supports single inheritance for classes: each class has exactly one direct superclass, except Object at the top of the hierarchy.
Are constructors inherited by subclasses?
Constructors are not inherited. A subclass constructor must initialize the superclass portion, usually by calling an appropriate superclass constructor with super(...).
What does super(...) do in a constructor?
super(...) calls a constructor in the direct superclass and must be the first statement in the subclass constructor. If omitted, Java attempts to insert super().
How do this(...) and super(...) differ?
this(...) calls another constructor in the same class, whereas super(...) calls a constructor in the direct superclass. Either call must be the first statement.
How can a subclass use a private superclass field?
A subclass cannot directly access a private superclass field. It must use an accessible method, such as a public or protected accessor or controlled operation.
What makes a method an override?
A subclass overrides an inherited instance method by using the same name and parameter list, with the same or a covariant return type and no weaker access.
How do overloading and overriding differ?
Overloading uses different parameter lists, usually resolved at compile time. Overriding uses the same parameter list in a subclass and enables runtime polymorphism.
What do reference type and runtime type control?
For Animal pet = new Dog(), the reference type is Animal and the runtime object type is Dog. The reference type controls accessible members; the runtime type selects overridden instance methods.
What does Animal a = new Dog(); a.speak(); execute?
Calling a method through an Animal reference that refers to a Dog runs Dog's overridden instance method. This runtime selection is dynamic dispatch, or late binding.
Why is upcasting safe?
Upcasting assigns a subclass object to a superclass reference, such as Animal animal = dog. It is safe because every subclass object is also a superclass object.
When can a superclass reference be downcast safely?
Downcasting is valid only when the referenced object is actually an instance of the target subclass. Otherwise, the cast can throw ClassCastException; use instanceof when a check is needed.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A structured guide to the digital divide, its causes and consequences, the distinction between digital equality and digital equity, and strategies for expanding meaningful participation in digital society.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A clear guide to how crowdsourcing and collective intelligence work, where they are applied, how contributions are evaluated, and how projects can manage risks and ethical responsibilities.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.
A structured guide to how routers select paths, exchange reachability information, apply routing policy, recover from failures, and diagnose connectivity problems across interconnected networks.