Question

Question 2 (1 point) Saved Choose the option that best describes what happens when the bolded println() statement is executedQuestion 4 (1 point) Assuming that Chicken extends Bird, and Bird extends Animal, choose the variable declaration that causesQuestion 5 (1 point) How do exceptions differ from errors in Java? A method can recover from an Error but not an Exception. E

please help

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2. Java systhesizes a toString() method for us with default behaviour, and that gets called.

Explanation:

In java, if object is printed then toString() method is directly invoked by the compiler. You can see the executed code with it's output in the picture below.

9 Execute > Share e File STDIN 1. public class Point{ 5 public static void main(String []args) { Point p1 = new Point(3, 4);

3. The compiler enforces that checked exceptions are caught or thrown.

Explanation:

Checked exceptions are checked at compile time and they are forced by java compiler to be caught or thrown in the method signature(using throws keyword). For example IOException, SQLException etc are checked exceptions.

4. The variable declaration which causes compile time error is:

Chicken clara = new Bird();

Explanation:

You can refer the below executed code and it's output. Explanation is added in the comments.

1 } 5 } Execute > Share e File STDIN class Animal 2. public Animal 3 System.out.println(Animal); 4 } 6. class Bird extends} Execute > Share e File STDIN 1. class Animal 2. public Animal({ 3 System.out.println(Animal); 4 } 5} 6. class Bird extend

5. Difference between errors and exceptions in java is:

Exceptions are throwable, errors are not.

Other options are not correct because

-> Errors cannot be recovered.

-> Error and RuntimeException classes are unchecked, everything else in Throwable class is checked.

-> Exceptions are thrown as a result of a problem with the JVM.

Add a comment
Know the answer?
Add Answer to:
please help Question 2 (1 point) Saved Choose the option that best describes what happens when...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

    Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...

  • In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static...

    In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static void main(String[] args) { String[] equations ={"Divide 100.0 50.0", "Add 25.0 92.0", "Subtract 225.0 17.0", "Multiply 11.0 3.0"}; CalculateHelper helper= new CalculateHelper(); for (int i = 0;i { helper.process(equations[i]); helper.calculate(); System.out.println(helper); } } } //========================================== public class MathEquation { double leftValue; double rightValue; double result; char opCode='a'; private MathEquation(){ } public MathEquation(char opCode) { this(); this.opCode = opCode; } public MathEquation(char opCode,double leftVal,double rightValue){...

  • Lab 1.java only Goal: This lab will give you experience with defining and using classes and...

    Lab 1.java only Goal: This lab will give you experience with defining and using classes and fields, and with conditionals and recursive functions. Getting Started --------------- Read the Fraction.java class into a text editor and compile it filling in the command javac -g Fraction.java. The program should compile without errors. In a shell window, run the program using "java Fraction". The program should run, although it will print fractions in a non-reduced form, like 12/20. Part I: Constructors (1 point)...

  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank...

    Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank you. What the tester requires: The AccountTester This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method. User and Bot information will be read from a file. A sample file is provided. Use this file format to aid in grading....

  • Please help!!!!!! import java.util.Random; public class CSE205_Assignment04 { private static Random rnd = new Random(); public...

    Please help!!!!!! import java.util.Random; public class CSE205_Assignment04 { private static Random rnd = new Random(); public static void main(String[] args) { Tree_ctor_test(); Tree_insert1_test(); Tree_insert3_test(); Tree_insertMany1_test(); Tree_insertMany2_test(); Tree_insertMany3_test(); Tree_insertMany4_test(); } public static void Tree_ctor_test() { Tree<Integer> t = new BSTree<Integer>(); assertEqual("", t.toString(), "Tree_ctor_test: toString", false); assertEqual(false, t.contains(0), "Tree_ctor_test: contains", false); } public static void Tree_insert1_test() { Tree<Integer> t = new BSTree<Integer>(); t.insert(1); assertEqual("1 ", t.toString(), "Tree_insert1_test: toString", false); assertEqual(false, t.contains(0), "Tree_insert1_test: contains", false); assertEqual(true, t.contains(1), "Tree_insert1_test: contains", false); } public static...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • QUESTION 13 A constructor is the same as any other method definition EXCEPT for what? A...

    QUESTION 13 A constructor is the same as any other method definition EXCEPT for what? A constructor includes an optional argument list. A constructor includes an optional access modifier, usually public. A constructor includes a return type. A constructor places arguments within parentheses (). 2 points    QUESTION 14 Using the asterisk wildcard (e.g. import com.packageName.*) will include all of the classes within packageName, even if they aren’t used. True False 2 points    QUESTION 15 The Random class gives...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT