Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 13.5, Problem 13.5.4CP
Program Plan Intro
Given Code:
//interface definition
interface A
{
//function declaration
void m1();
//close class
}
//class declaration to implement interface
class B implements A
{
//function call
void m1()
{
//print m1
System.out.println("m1");
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given:
interface B
void methodA();
class C implements B
{
void methodB(){ }
}
everything is fine
methodA should be overriden in class C
O class C should be abstract
O either b or c
Take a look at the following code:
class Test5 extends Test4{
private int j;
Il add a constructor correctly
class Test4 {
int i;
Test4 (int m){
i= m;
}
public void printVal(){
public void printVal(){
System.out.printIn(6);
System.out.println(i);
public void printSum(){
}
System.out.printin(i+j);
}
}
Write two overloaded constructors for class Test5 - one taking no
parameters and other taking 2 integer parameters to set the values of i
and j. (Hint: you have to use super as the superclass has a constructor
now that takes a parameter). Also write a main function that creates one
Test4 object and one Test5 object. Then print the sum using the
printSum() function. Also show the output if your code is run.
class overload
{
int x;
double y;
void add(int a , int b)
{
x = a + b;
}
void add(double c , double d)
{
y = c + d;
}
overload()
{
this.x
0;
%3D
this.y = 0;
}
%3D
}
class Overload_methods
{
public static void main(String args[])
{
overload obj
int a = 2;
double b - 3.2;
obj.add(a, a);
obj.add(b, b);
System.out.println(obj.x +
}
= new overload();
+ obj.y);
}
#3Run the code
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Knowledge Booster
Similar questions
- Given: abstract class A{ int a; int b; } class B extends A{ int a; } O cannot make class A abstract can create an instance of both class A and class B class B must also be abstract O cannot make an instance of class Aarrow_forwardX2, Y2------1.arrow_forwardStatement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forward
- class Param3 { public int x; private void increase(int p) { x = x*p; } public void calculateX(int y) { increase(y); } public int getX() { return x; } } // in another class Param3 q3 = new Param3(); q3.x = 5; q3.calculateX(7); System.out.println(q3.getX()); what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?arrow_forwardclass A{ int a; int b; } class B extends A{ int a; public static void main(String[] args){ B obj=new B(); } } How do you get access to the variable "a" in class A? use obj.a use obj.super.a create an object of type A and then reference the variable O both b and carrow_forward1(c). What is the problem with the code below? Write two different ways to fix the problem. (5) interface A { interface B { default void f () { System.out.println("A's f"); } default void f () { System.out.printIn("B's f"); } } } public class C implements A, B {arrow_forward
- i. Identify the subclass and superclass. ii. Create other class named Triangle that inherits the properties from the superclass. Calculate the area of Triangle in instance method and instantiates object for Triangle class accordingly in main class.arrow_forward1) The following is a valid interface definition in Java public interface Shape { default public double getArea(); public double getPerimeter() } Select one: True False 2) You can use the following method header to override the equals method in Object class: protected equals(Object obj) Given that the class (wherein this method is defined) implements the Comparable interface 3) Based on the below code: Restaurant res=new Restaurant("Default Name"); Restaurant.Address add=res.new Address(new City()); The class city is: Select one: a. A part-of Class Address b. An inner Class to Class Address c. An inner Class to Class Restaurant d. None of thesearrow_forwardpublic class A { public void funl () { System.out.println ("Al"); } public class B extends A { @Override public void funl () { super.fun1 () ; System.out.println ("B1"); public void fun2 () { System.out.println ("B2"); public class C extends B { @Override public void funl () { System.out.println ("C1");arrow_forward
- 2. Using Encapsulation concept for Test1 class. package Exam; public class Test1 { private static int index = 0; public int x; Test1(){ index ++; } public static int getlndex () { return index; } public void prints(){ System.out.println("Hi Students!"); } } public class Test2 extends Test1 { @Override public void prints(){ System.out.println("OOP!"); } } public class Main { public static void main(String[] args) { } }arrow_forwardWrite a class named IceCreamCup that implements the Customizable interface. The class should have the following private instance variables. Do NOT give any method implementations for this question, but only declare the instance variables. Do NOT initialize the instance variables -- except nCups below. A String variable name describing the ice cream name • A List of Flavor s added to the cup. Name it flist Additionally, define the following static variable: • An int nCups describing the total number of ice cream cups instantiated. Initialize this variablearrow_forwardInheritance is a mechanismin which one class acquires the property of an other class. For example, a child inherits the traits of his/her parents. (a) Understand the program code below in Figure 1 and answer the following questions. class shape { protected int length, width; void set (int a, int b) { length width = b; } void show () = a; { System.out.println (length+" "+width); }} class rectangle extends shape { int area; void setArea () { area= length*width;} void show () { System.out.println (area); }} class AreaRec{ public static void main (String [] args) { rectangle r= new rectangle () ; r. Set (4,10); r. Show () ; r. SetArea () ; r. Show () ; }} Figure 1: Rectangle area i. Identify the output of the program above. Please show the tracing table.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education