[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 15 KB, 276x183, index.jpg [View same] [iqdb] [saucenao] [google]
6126838 No.6126838 [Reply] [Original]

Sup /sci/ need help with a computer science lab dealing with variable scoping heres the code
lic class Scoping {
static double a = 123; /* ....................... location (1) */

public static void F( double a ) /* ....................... location (2) */
{
System.out.println("------ inside F( double a ) !!!!!!!!!!!!!!!!");

System.out.print("a at (2) = ");
// TODO: Write a System.out.println() statement that prints a on location (2)
System.out.println(a);
System.out.print("a at (1) = ");
// TODO: Write a System.out.println() statement that prints a on location (1)
System.out.println(a);
}

public static void F( String a ) /* ....................... location (3) */
{
System.out.println("------ inside F( String a ) ");

System.out.print("a at (3) = ");
// TODO: Write a System.out.println() statement that prints a on location (3)
F(a);
System.out.println(a);

System.out.print("a at (1) = ");
// TODO: Write a System.out.println() statement that prints a on location (1)
System.out.println(a);

How do i reference a in position one in different palces i nthe code?

>> No.6126842

self bump

>> No.6126868

>>6126838
since a in location 1 is an attribute, you can use "this" to reference that attribute:

public int F(double a){
System.out.println("This is the parameter a " + a);
System.out.println("This is the attribute a " + this.a);
}
}

>> No.6126960
File: 210 KB, 1024x768, Jshit.jpg [View same] [iqdb] [saucenao] [google]
6126960

>>6126838
>computer science
> Java

Get the fuck out and never come back here