PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 20, 2022

[FIXED] What is the difference between assigning an instance variable before and after parameter?

 October 20, 2022     datamember, function, java, oop     No comments   

Issue

What is the difference between assigning a parameter to an instance variable? Why is it wrong when you write the parameter before the instance variable?

int variable; 

void set(int parameter)
{
    variable = parameter;
    parameter = variable; 
}

Solution

Case 1:

int variable;

void set(int parameter)
{
    variable = parameter;
}

Case 2:

int variable;

void set(int parameter)
{
    parameter = variable;
}

Both cases are correct by Java syntax, but case 2 has very little logical value...

The case 2 method parameter has a value and we need to use it. but before using this value, we change this by assigning variable, so we lost the previous value.



Answered By - Istiaque Hossain
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing