13th Feb 2021, 12:30 PM
Kajal Kumari
3 ответов
+ 2
you should use 'this' keyword to access instance properties (wich should be defined in the class): public class Box10 { int x; int y; public void getdata() { Scanner input = new Scanner(System.in); System.out.println("enter two numbers"); this.x = input.nextInt(); this.y = input.nextInt(); } public void showdata() { System.out.println("the entered number"+this.x); System.out.println("the entered number:"+this.y); } }
13th Feb 2021, 12:37 PM
visph
visph - avatar
+ 2
Kajal Kumari int x and int y declared local variable. You can't access in another method.
13th Feb 2021, 12:38 PM
A͢J
A͢J - avatar
+ 2
Thanks
13th Feb 2021, 12:40 PM
Kajal Kumari