Most difficult Question in Java Observe Carefully the Question like and share | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Most difficult Question in Java Observe Carefully the Question like and share

class demo { int x=5; demo() { System.out.println(x); } void demo() { System.out.println(x); } public static void main(String arts[]) { demo ob = new demo(); ob.demo() } }

6th Nov 2016, 1:47 PM
Jenny Lance
Jenny Lance - avatar
6 Answers
+ 2
what is the output? I'm not getting
6th Nov 2016, 2:23 PM
Jenny Lance
Jenny Lance - avatar
+ 2
you should write ob.demo(); its output is 5 5
6th Nov 2016, 2:27 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
many error in there, first you have 2 method (demo & void demo) but the demo method is error because the method need the type of method ,such (void,int,double,string), second you call a method that does not exist "ob.Demo" which should "ob.demo" ,third you declare unclear variable, fourth you can include a new class for main method or you can change all of code to reduce the error sorry my bad english
6th Nov 2016, 2:32 PM
Edbert andoyo
Edbert andoyo - avatar
0
You have define demo function and calling Demo function. Java is strong typed language. Anyway whats your problem please explain it.
6th Nov 2016, 2:14 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
5 5
31st Dec 2016, 9:04 PM
Akshay Jain
Akshay Jain - avatar
0
There is nothing wrong with this code. Just a typo ob.demo() needs a ; This will outputs 5 5 demo() is a class constructor not a method. But void demo() is a method of the class.
10th Feb 2017, 3:40 AM
Sinan Ceylan
Sinan Ceylan - avatar