Given that the class Circle extends the abstract class Shape, which of the following lines would instantiate object of these classes?
Shape s = new Shape(); |
||
Circle c = new Shape(); |
||
Shape s = new Circle(); |
||
None of the answers |
The correct answer is:
1) Shape s = new Shape(); would instantiate an object of class Shape
2) Circle c = new Shape(); will throw compilation error.
3) Shape s = new Circle(); would instantiate an object of class Circle, and hence this statement is correct.
Given that the class Circle extends the abstract class Shape, which of the following lines would...
java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Define an abstract base class SHAPE that includes protected data members for the (x,y) position of a shape, a public method to move a shape , and a public abstract method show() to output a shape .Derive subclasses for lines, circles and rectangles. Also define the class POLYLINE with SHAPE as the base class. You can represent a line as two points, a circle as a center and a radius. A rectangle as two points on diagonally opposite corners. Implement...
TASK 1: Create class diagram for abstract class Shape. TASK 2: Create class diagrams for abstract subclasses TwoDimensionalShape and ThreeDimensionalShape which extend abstract superclassShape. TwoDimensionalShape contains method getArea, and ThreeDimensionalShape contains methods getArea and getVolume. TASK 3: Create class diagrams for concrete classes Circle, Square, Triangle, Sphere, Cube and Tetrahedron.
JAVA CODING: (14 points) Abstract Class exercise You are given two abstract classes with no abstract method in the NoGo.java file. The purpose of this exercise is to get familiar with abstract class and its object creation 4. Follow the steps below: (be sure common on each to score points) 1) 2) 3 points) Create a subclass Go1 with Nogo1 as its super class and create Go1() constructor 3) (2 points) Now inside the NoGo class create an instance of...
Java programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input....
Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...
c++ 6. Define classes shape, and classes circle and square, which inherit from shape. At the bottom of the page is a sample program using these classes, followed by its output. (a) Class shape has abstract virtual constant functions area and border which do not take arguments and which return double. It has a virtual constant function where which has no arguments and returns its lo- cation. It has a private field of type location and a ctor which accepts...
Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...
what is abstract class in java? for example, abstract class animal and subclass cat which extends abstract class, and the test class which will call cat class to show if it yawns, scratch and whatnot. I used to create class animal but it was not abstract, so I am not sure the purpose of it. Another question, I created interface, by right clicking the package, I think the teacher saying interface is acts independent? and not part of hierarchy like...
For Java, 1. What is an abstract method? How is an abstract method created? 2. What is an abstract class? 3. Can an object of an abstract class be instantiated? 4. Does a superclass have access to the members of subclass? Does a subclass have access to the members of the superclass? 5. How do you prevent a subclass from having access to a member of a superclass? 6. Given the following hierarchy: class Alpha{ … class Beta extends Alpha...