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 3 of 3

Thread: Basic Java Question

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

    Default Basic Java Question

    I was given this question and was hoping someone could please explain this Java class so I can understand. Thank you, J

    JAVA CONCEPTS | SCOPING public class MyClass {     public static int num;          public static int getNum() {         num = 3;         if( true ) {             int num;             num = 10;         }         return num;     } }

    Given the above Java class, what is the return value for MyClass.getNum()?

  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: Basic Java Question

    It will return the value of the class-level static variable num, which was set to 3 initially.
    Whatever you are, be a good one

  3. The Following User Says Thank You to John Joe For This Useful Post:

    jjevans (March 29th, 2024)

  4. #3
    Junior Member
    Join Date
    Mar 2024
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Question

    Thank you for your insight.

Similar Threads

  1. Basic Java Question
    By chaoticcircuit in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 3rd, 2014, 12:18 AM
  2. basic java question
    By jim213mm in forum Java Theory & Questions
    Replies: 2
    Last Post: January 19th, 2012, 01:30 PM
  3. Basic Java question
    By fred2028 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 13th, 2011, 03:54 PM
  4. Basic java question
    By erosgol in forum Java Theory & Questions
    Replies: 5
    Last Post: September 2nd, 2011, 05:24 PM
  5. Very new to Java basic question
    By loofy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 23rd, 2011, 06:21 PM