Hands-On Brain class assignment 7---------

Source: Internet
Author: User

Hands on the brain 1

Catchwho.java Running results:

Catchwho2.java Running results:

Embedefinally.java Running results:

is the finally statement block bound to execute?

Systemexitandfinally.java Running results:

Thefinally statement block executes only if the try statement block corresponding to finally is executed . if a Try statement block is returned (return) or an exception is thrown,thetry corresponds to the finally The statement block is not executed.

Hands on the brain 2

How do I track the propagation path of an exception?

    • When an exception occurs in the program, the JVM looks for the error handler in order of the method invocation.
    • You can use the Printstacktrace and GetMessage methods to understand what happens when an exception occurs:
      • Printstacktrace: Prints the method call stack.
      • Each object of the Throwable class has a GetMessage method that returns a string that is passed in the exception constructor and typically contains information about a particular exception.

Printexpressionstack.java Running results:

Hands on the brain 3

Answer the question

. What is the result of running the program on the left?

2. How do you explain that you will get such output?

When called, the object is a subclass of the method that calls the subclass, and the object is the parent class's method of calling the parent class.

3. The computer is not wrong, the reason why you get such a running result is also a reason, then from these running results, you can summarize the Java syntax features?

1 When a subclass has the same method as the parent class, and when a parent class variable refers to a subclass object, which method is called, determined by the object's own "true" type, that is, the object is a subtype, it calls the method of the subtype, it is the parent type, and it invokes the method of the parent type. This feature is actually a concrete representation of the object-oriented "polymorphic" feature.

2 If a subclass has the same field as the parent class , the fields in the subclass are substituted or hidden from the parent class, and the subclass method accesses the fields in the subclass (not the fields in the parent class). If the subclass method does want to access a field that is hidden in the parent class with the same name, it can be accessed with the super keyword.

3 If a subclass is used as a parent class , the field accessed through the subclass is the parent class .

Hands-On Brain class assignment 7---------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.