Ok, so I am revisiting java after many years and I was just trying out some random program when I found out that I was having an error in the following snippet. Can someone give me any heads on how to solve this? I know that static methods will not be able to access non static variables but I created an instance for it right? Also I am not getting any heads on reading some other questions so try to help me.
import java.io.*;
public class phone
{
int x=6;
int getx()//I also tried using this function but everything in vain
{
return x;
}
}
public class Testing_inheritance extends phone
{
public static void main (String args[])throws IOException
{
phone xy=new phone();
int y=phone.x;
y+=10;
System.out.println("The value of x is " +y);
}
}
int y=phone.x;should probably beint y=xy.x;.