Inheritance, Polymorphism and Scope
Not what you're looking for?
Example 1: Which access modifier (public, private, protected, default) would you use on a data field in the following cases?
a. You plan to inherit from this class from without the package.
b. You want only those classes within the package to have access to this field.
c. You want to restrict access to within the class itself.
d. The client should have access to this field.
Example 2: Examine the following driver for classes Book and LibBook and determine what is printed
// Class TestBook is a driver for classes
// Book and TestBook
import java.util.Scanner;
public class TestBook
{
public static void main(String[] args)
{
LibBook first;
Book second;
first =
new LibBook("How to Solve It",
"G. Polya",
"0-691-02356-5",
2, 511);
second =
new Book("Programming and Problem Solving with Java",
"Nell Dale and Chip Weems",
"10: 0-7637-3402-0");
System.out.println("Book object: " + "n" + second);
System.out.println("LibBook object: " + "n" + first);
}
}
Purchase this Solution
Solution Summary
The expert examines inheritance, polymorphism and scope.
Solution Preview
Example #1
a. protected
b. package
c. private
d. public
Example #2
The output ...
Purchase this Solution
Free BrainMass Quizzes
C++ Operators
This quiz tests a student's knowledge about C++ operators.
Excel Introductory Quiz
This quiz tests your knowledge of basics of MS-Excel.
Javscript Basics
Quiz on basics of javascript programming language.
Basic Computer Terms
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.