0% found this document useful (0 votes)
36 views3 pages

Chapter 4 JAVA OOP Features: 2.1 Questions

The document provides homework questions on Java OOP features including inheritance, polymorphism, access modifiers, preventing class extension and overriding methods. It asks students to implement Circle and Rectangle classes that extend the GeometricObject class based on the provided UML diagram. Additional programming problems involve randomly filling a matrix with 0s and 1s and finding maximum rows and columns, removing duplicate elements from an arraylist, and calculating the area of a convex polygon by user input points. Students are instructed to complete the problems locally and submit their code and report by the given deadline.

Uploaded by

creation portal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Chapter 4 JAVA OOP Features: 2.1 Questions

The document provides homework questions on Java OOP features including inheritance, polymorphism, access modifiers, preventing class extension and overriding methods. It asks students to implement Circle and Rectangle classes that extend the GeometricObject class based on the provided UML diagram. Additional programming problems involve randomly filling a matrix with 0s and 1s and finding maximum rows and columns, removing duplicate elements from an arraylist, and calculating the area of a convex polygon by user input points. Students are instructed to complete the problems locally and submit their code and report by the given deadline.

Uploaded by

creation portal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Chapter 4 JAVA OOP Features

1. Slides

2. Homework

2.1 Questions

1. What keyword do you use to define a subclass?


2. What is single inheritance? What is multiple inheritance? Does Java support
multiple inheritance?
3. How do you explicitly invoke a superclass’s constructor from a subclass?
4. What is polymorphism? What is dynamic binding?
5. Describe the difference between method matching and method binding.
6. Does every object have a toString method and an equals method? Where do they
come from? How are they used? Is it appropriate to override these methods?
7. What modifier should you use on a class so that a class in the same package can
access it, but a class in a different package cannot access it?
8. What modifier should you use so that a class in a different package cannot access
the class, but its subclasses in any package can access it?
9. How do you prevent a class from being extended? How do you prevent a method
from being overridden?

2.2 Programming

1. (The Circle class and the Rectangle class) Design two classes named Circle and
Rectangle that extend GeometricObject class. The UML diagrams for the
classes Circle , Rectangle and GeometricObject are shown below:

Please write a program and implement the classes.

2. (Largest rows and columns) Write a program that randomly fills in 0s and 1s
into an n-by-n matrix, prints the matrix, and finds the rows and columns with the
most 1s. (Hint: Use two ArrayLists to store the row and column indices with the
most 1s.) Here is a sample run of the program:
3. (Remove duplicates) Write a method that removes the duplicate elements from
an array list of integers using the following header:

public static void removeDuplicate(ArrayList<Integer> list)

Write a test program that prompts the user to enter 10 integers to a list and
displays the distinct integers separated by exactly one space. Here is a sample run:

4. (Area of a convex polygon) A polygon is convex if it contains any line segments


that connects two points of the polygon. Write a program that prompts the user to
enter the number of points in a convex polygon, then enter the points clockwise,
and display the area of the polygon. Here is a sample run of the program:

We won’t use online judge in this homework, so you should write your programs in
your local environment.

This homework’s deadline is 2020.11.10 23:59:59, submit your code and report to
my email([email protected]) on time please!

You might also like