+ 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() } }
6 ответов
+ 2
what is the output? I'm not getting
+ 2
you should write
ob.demo();
its output is
5
5
+ 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
0
You have define demo function and calling Demo function. Java is strong typed language. Anyway whats your problem please explain it.
0
5
5
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.