Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: will the result always be true?

  1. #1
    Junior Member
    Join Date
    Apr 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question will the result always be true?

    public class Main {
    public static void main(String[] args) {
    A a =null;
    try{
    a = new A(1);
    }catch (IOException e) {
    System.out.println(a == null);
    }

    }
    }

    class A {
    private int v;
    public A(int val) throws IOException {
    v= val;
    throw new IOException("123");
    }
    }

    as far as i know
    the process of new a object has 3 steps:
    1. allocate memory
    2. execute construct function
    3. assign to reference

    due to instruction reordering, the process may be changed to 1->3->2 rather than 1->2->3.
    so will the result of the code above always be true?

    sorry for my english

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: will the result always be true?

    Why don't you try to run using IDE?
    Whatever you are, be a good one

Similar Threads

  1. Is it true...
    By spock++99 in forum The Cafe
    Replies: 0
    Last Post: November 9th, 2020, 08:37 AM
  2. Which of the following propositions is true
    By tornado in forum Object Oriented Programming
    Replies: 3
    Last Post: May 20th, 2014, 11:44 AM
  3. True and False that
    By kindon in forum Totally Off Topic
    Replies: 0
    Last Post: December 6th, 2013, 06:33 PM
  4. Help me to get true value.
    By Zimmer in forum Java Theory & Questions
    Replies: 4
    Last Post: May 8th, 2013, 01:01 PM

Tags for this Thread