Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.7, Problem 9.7.3CP
Can you invoke an instance method or reference an instance variable from a static method? Can you invoke a static method or reference a static variable from an instance method? What is wrong in the following code?
- 1. public class C {
- 2. public static void main(String[) args) {
- 3. method1();
- 4. }
- 5.
- 6. public void method1 () {
- 7. method2();
- 8. }
- 9.
- 10. public static void method2() {
- 11. System.out.println( "What is radius" + c.getRadius());
- 12. }
- 13.
- 14. Circle c new Circle();
- 15. }
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Method Overloading is a feature that allows a class to have two or more methods having
same name, if their argument lists are different. Argument lists could differ in:
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
Write different version of method sum() that display the sum of the values received as
parameter according to the following main method content:
public static void main(String[] args)
{
sum ( 10, 10 );
sum ( 10, 10, 10 );
sum ( 10.0, 10.0 );
sum ( 10, 10.0 );
sum ( 10.0, 10);
}
You have to define five functions with the specified types. Then, demonstrate the Argument
Promotion concept by reducing the number of method to two.
private float c;
private void method2(double y) {
c = y;
}
in another class we created an object of the first class then within in it :
tester.method2 (10.0f);
are there any errors ? how many errors if there are any and with explanation please.
private int b;
public int method3()
{
return b;
}
// in another class an object of the first class was introduced and inside the second class :
float y = tester.method3();
are there any errors ? and explain please
Chapter 9 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Ch. 9.3 - Prob. 9.3.1CPCh. 9.3 - How do you define a class?Ch. 9.3 - How do you declare an objects reference variable?Ch. 9.3 - How do you create an object?Ch. 9.4 - Prob. 9.4.5CPCh. 9.4 - When will a class have a default constructor?Ch. 9.5 - Which operator is used to access a data field or...Ch. 9.5 - What is an anonymous object?Ch. 9.5 - Prob. 9.5.3CPCh. 9.5 - Is an array an object or a primitive-type value?...
Ch. 9.5 - Prob. 9.5.5CPCh. 9.5 - What is wrong in the following code? 1. class Test...Ch. 9.5 - Prob. 9.5.7CPCh. 9.6 - Prob. 9.6.1CPCh. 9.6 - Prob. 9.6.2CPCh. 9.6 - Which packages contain the classes Date, Random,...Ch. 9.7 - Suppose the class F is defined in (a). Let f be an...Ch. 9.7 - Prob. 9.7.2CPCh. 9.7 - Can you invoke an instance method or reference an...Ch. 9.9 - Prob. 9.9.1CPCh. 9.9 - Prob. 9.9.2CPCh. 9.9 - In the following code, radius is private in the...Ch. 9.10 - Prob. 9.10.1CPCh. 9.10 - Show the output of the following program: public...Ch. 9.10 - Show the output of the following code:Ch. 9.10 - Prob. 9.10.4CPCh. 9.11 - What is wrong in the following code? 1public class...Ch. 9.12 - If a class contains only private data fields and...Ch. 9.12 - If all the data fields in a class are private and...Ch. 9.12 - Is the following class immutable? public class A {...Ch. 9.13 - What is the output of the following program?...Ch. 9.14 - Prob. 9.14.2CPCh. 9.14 - Prob. 9.14.3CPCh. 9 - (The Rectangle class) Following the example of the...Ch. 9 - (The Stock class) Following the example of the...Ch. 9 - (Use the Date class) Write a program that creates...Ch. 9 - Prob. 9.4PECh. 9 - (Use the GregorianCa1endar class) Java API has the...Ch. 9 - (Stopwatch) Design a class named StopWatch. The...Ch. 9 - (The Account class) Design a class named Account...Ch. 9 - (The Fan class) Design a class named Fan to...Ch. 9 - (Geometry: n-sided regular polygon) In an n-sided...Ch. 9 - Prob. 9.10PECh. 9 - (Algebra: 2 2linear equations) Design a class...Ch. 9 - (Geometry: intersecting point) Suppose two line...Ch. 9 - (The Location class) Design a class named Location...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Run the hello, world program on your system. Experiment with leaving out parts of the program, to see what erro...
C Programming Language
Describe statement-level consistency.
Database Concepts (8th Edition)
What import statement will you need in a program that performs file operations?
Starting Out with Java: Early Objects (6th Edition)
Explain why incremental development is the most effective approach for developing business software systems. Wh...
Software Engineering (10th Edition)
Write a programming statement that gives the focus to a TextBox control named txtNumber.
Starting Out With Visual Basic (7th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- I am getting an error Error: Main method not found in class Course, please define the main method as: public static void main(String[] args)arrow_forwardJavaarrow_forwardpublic class A { public static void methodl () { } } public class B { System.out.println("B1"); public static void methodl () { } System.out.println("C2"); public class C { } public static void methodl () { System.out.println("B1"); } And assuming the following objects have been defined: A a = new A(); B b = new B(); B other2 = new C(); In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement causes an error, fill in the right-hand column with either the phrase "compiler error" or "runtime error" to indicate when the error would be detected. Statement Output a.methodl (); a.method2 (); b.methodl (); b.method2(); other2.methodl (); other2.method2 ();arrow_forward
- Overloading a method and overriding a method are two separate but related concepts.arrow_forwardWhat is the error in the code below? public class Test { public static int calcProfit (int x) { // method body omitted to save space } public static int calcProfit (int y) { // method body omitted to save space } }arrow_forwardCan we override static methods of a class?arrow_forward
- True or False: An abstract method has no body.arrow_forwardpublic class CallStack{ // Called by func1() void func2 (){ System.out.println("In func2 method"); int a = 0; int b; b = 10 / a; } //Called by Main void func1(){ System.out.println("In func1 method"); this.func2 (); System.out.println("Back in func1 method"); } public static void main (String args[]){ CallStack myCallStack; myCallStack = new CallStack(); System.out.println("In the main method"); try { myCallStack.func1 (); }catch (ArithmeticException e) { System.out.println("Can't divide by Zero!"); } } } Examine the code to determine what it does. Compile and execute the code. Modify the main() method to handle the exception that is propagated to it. Use a try- catch block to display a meaningful error message when the exception occurs. Test your code. Notice that, although the exception was thrown in func2, it is caught by the catch block in the main method.arrow_forwardpublic class Base public void methodOne () { System.out.print ("A"); methodTwo (); } } public void methodTwo () { System.out.print("B"); } public void methodThree () { } public void methodThree (String s) { System.out.print("Hello, " + s); } System.out.print("Hello"); } class Derived extends Base { public void methodOne () { super.methodOne (); System.out.print ("C"); } public void methodTwo () { super.methodTwo (); System.out.print("D"); What is the name of the parent class? What is the name of the overloaded method? What is the name of the overriden method? What is the name of the child class? ich of Choose... Choose... Choose... Choose... following statements will give an error?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License