0

What is the o/p of this programming code ??

class A { int x; A(int x) {x = x ;} void display() { System.out.println(x); } } public class B { public static void main(String[] args) { A a = new A(7); a.display(); } }

21st Dec 2016, 3:55 PM
Mangesh Prajapati
Mangesh Prajapati - avatar
4 Respostas
+ 1
You've tag your question with "javascript" and "java" Oo ! This is java, not javascript : totally differents ones ^^ Try to replace {x = x ;} by {this.x = x ;} Else you attribute the value of your parameter to... your parameter :P ( due to scope ) And maybe you need too to prefix your A class by the keyword "public" ?
21st Dec 2016, 4:09 PM
visph
visph - avatar
0
0
21st Dec 2016, 3:57 PM
Somnath Ghosh
Somnath Ghosh - avatar
0
use...this.x=x;........to get 7
21st Dec 2016, 3:58 PM
Somnath Ghosh
Somnath Ghosh - avatar
0
ohh ya this is absolutely right #somnath or visph and thanx for my mistake to tag a javascript
22nd Dec 2016, 6:06 AM
Mangesh Prajapati
Mangesh Prajapati - avatar