Sign Up

Continue with Facebook
Continue with Google
or use

Have an account? Sign In Now

Sign In

Continue with Facebook
Continue with Google
or use

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Continue with Facebook
Continue with Google
or use

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Ansfind

Ansfind Logo Ansfind Logo Ansfind Logo Ansfind Logo
Add question

Ansfind Navigation

  • About Us
  • Groups
    • Add group
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Hot Questions
  • Polls
  • Tags
  • Points
  • Users
  • FAQs
  • Help
  • Contact Us
SaRa
SaRaProfessor
Asked: September 6, 20212021-09-06T15:26:58+05:30 2021-09-06T15:26:58+05:30In: Education and learning

In which process, a local variable has the same name as one of the instance variables?

In which process, a local variable has the same name as one of the instance variables?
A) Serialization
B) Variable Shadowing
C) Abstraction
D) Multi-threading

variable shadowing
  • 3
  • 22
  • 346
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
Answer

    Related Questions

    • low compression in diesel engine
    • Differentiate the followiNG
    • What is the range of compression ratio

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. Dayana
      2021-09-08T11:15:49+05:30Added an answer on September 8, 2021 at 11:15 am

      Answer: option B) Variable Shadowing

      Variable Shadowing: If the local variable and instance variable have same name The value of the local variable will be printed(shadowing the instance variable), whenever you print (access) it in the method.

      Example:

      In the following Java example, the class ShadowTest has a method (show()). and two instance variables (name, age).

      In the show() method there are two variables same as the instance variables (name and age).

      When you invoke print (access) them in the method, the local variable values will be printed shadowing the instance ones.

      <span>public</span> <span>class ShadowTest</span><span>
      </span><span>{  
      </span><span>   String</span><span> name </span><span>=</span> <span>"Saru"</span><span>;</span>
         <span>int</span><span> age </span><span>=</span> 28<span>;</span>
         <span>public</span> <span>void</span><span> show</span><span>()
         {</span>
            <span>String</span><span> name </span><span>=</span> <span>"Varu"</span><span>;</span>
            <span>int</span><span> age </span><span>=</span> <span>21</span><span>;</span>
            <span>System</span><span>.</span><span>out</span><span>.</span><span>println</span><span>(</span><span>"Name: "</span><span>+</span><span>name</span><span>);</span>
            <span>System</span><span>.</span><span>out</span><span>.</span><span>println</span><span>(</span><span>"age: "</span><span>+</span><span>age</span><span>);</span>
         <span>}</span>
         <span>public</span> <span>static</span> <span>void</span><span> main</span><span>(</span><span>String</span><span> args</span><span>[])
         {</span>
            <span>new </span>ShadowTest<span>().show</span><span>();</span>
         <span>}</span>
      <span>}</span>
      copy the code and you can check the result Here

       

      • 3
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. Salomi
      2021-11-18T20:11:48+05:30Added an answer on November 18, 2021 at 8:11 pm

      Answer: (b) Variable Shadowing

       

      • 1
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Choose from here the video type.

    Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

    Sidebar

    Top Users

    Weboptify

    Weboptify

    • 3,290 Points
    Wish Lay

    Wish Lay

    • 2,360 Points
    Manu Murthy

    Manu Murthy

    • 1,635 Points

    Adv 250x250

    • About Us
    • Home
    • Communities
    • Polls
    • Tags
    • Points
    • Users
    • Help
    • Contact Us
    • Referrals
    • Policies
      • Privacy policy
      • Terms of use
    Revenue

    © 2022 Ansfind. | Designed by Weboptify

    monetization_on category home emoji_events
    search
    help

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.