1. Define \"Inheritance\" as it relates to the design of classes in Java. What b
ID: 3536209 • Letter: 1
Question
1. Define "Inheritance" as it relates to the design of classes in Java. What benefit does inheritance offer the programmer?
2.Explain what happens if an exception is not handled at the level at which it occurs. What if it is never handled?
3.What is the difference between "overloading" and "overriding" methods? Which specifically relates to inheritance and why?
4.Define the term "binding". How does this process relate to the polymorphism of an inheritance string?
5.What mechanism is used to create borders around swing components? Code an example of a component with a border.
6.From what class do all classes derive? What are some of the methods inherited? What should the derived class do with these methods?
7.What happens when an object is passed as a parameter to a method?
8.What are the three ways a programmer can deal with an exception?
9.Define "polymorphism" as it relates to classes and objects.
10.What purpose do layout managers serve? Name four (4) layout managers including the default layout manger (identify the default layout with *** following its name).
Explanation / Answer
8
If a checked exception is thrown in a method, it must be handled in one of three ways:
1.By using a try block and catching the exception in a handler and dealing with it
2.By using a try block and catching the exception in a handler, but throwing another exception that is either unchecked or declared in its throws clause
3.By explicitly allowing propagation of the exception to its caller by declaring it in the throws clause of its method header
Exceptions are the customary way in Java to indicate to a calling method that an abnormal condition has occurred. This article is a companion piece to this month's Design Techniques installment, which discusses how to use exceptions appropriately in your programs and designs. Look to this companion article for a tutorial on the nuts and bolts of what exceptions are and how they work in the Java language and virtual machine.
When a method encounters an abnormal condition (an exception condition) that it can't handle itself, it may throw an exception. Throwing an exception is like throwing a beeping, flashing red ball to indicate there is a problem that can't be handled where it occurred. Somewhere, you hope, this ball will be caught and the problem will be dealt with. Exceptions are caught by handlers positioned along the thread's method invocation stack. If the calling method isn't prepared to catch the exception, it throws the exception up to its calling method, and so on. If one of the threads of your program throws an exception that isn't caught by any method along the method invocation stack, that thread will expire. When you program in Java, you must position catchers (the exception handlers) strategically, so your program will catch and handle all exceptions from which you want your program to recover.
9
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. The concept of parametric polymorphism applies to both data types and functions. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. A data type that can appear to be of a generalized type (e.g., a list with elements of arbitrary type) is designated polymorphic data type like the generalized type from which such specializations are made.
There are several fundamentally different kinds of polymorphism, two of which were originally informally described by Christopher Strachey in 1967. If the function denotes different and potentially heterogeneous implementations depending on a limited range of individually specified types and combination, it is called ad-hoc polymorphism. Ad-hoc polymorphism is supported in many languages using function and method overloading.
If all code is written without mention of any specific type and thus can be used transparently with any number of new types, it is called parametric polymorphism. John C. Reynolds (and later Jean-Yves Girard) formally developed this notion of polymorphism as an extension to lambda calculus (called the polymorphic lambda calculus, or System F). Parametric polymorphism is widely supported in statically typed functional programming languages. In the object-oriented programming community, programming using parametric polymorphism is often called generic programming.
In object-oriented programming, subtype polymorphism or inclusion polymorphism is a concept in type theory wherein a name may denote instances of many different classes as long as they are related by some common super class.[1] Inclusion polymorphism is generally supported through subtyping, i.e., objects of different types are entirely substitutable for objects of another type (their base type(s)) and thus can be handled via a common interface.
Interaction between parametric polymorphism and subtyping leads to the concepts of bounded quantification and covariance and contravariance (or polarity) of type constructors.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.