• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tried modifying println function  RSS feed

 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created problem for myself by writing a java program of class System in which i used out as a static variable of Printstream type and in static block i initialised it with =new Printstream ()
in Printstream class i used a function println function with int var as its argument another temp class containing main function in which i used
System.out.println (20);

Output i got as
at.printstream.out (20)
And now whenever in any program i use println function i get same error even deleted the previous file but no use having same error
Help me out
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code in code tag so who knows the answer will help you to figure out that.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Knute Snortum
Sheriff
Posts: 4284
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags (← That's a link) and indent properly when you post a program. I did it for you this time.

Are all the classes removed? What is the complete error message (stack trace)?
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do one thing delete all .class files i.e. System.class, Printstream.class and their .java also( Only of these two classes) and also delete Temp.class and remove System, Printstream class from code and compile and run program.
 
Sachin Tripathi
Ranch Hand
Posts: 368
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya thankyou Snortum
I had just removed the class containing main after removing all class
it started working again
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And did that code actually execute?
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it executed and gave output as: at Printstream.println(Test.java:14)
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is part of the stack trace. What sort of Exception did you suffer? Stack Overflow Error?

I hope that shows you what can go wrong if you create classes with the same name as those in the packages you are importing.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your thread title is incorrect. You are not modifying println at all. You are creating a new method which happens to have the same signature.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Tripathi wrote:

Do you see what this code does?

Line 22: you call your own println method defined in lines 12-15.

Line 14: you think that you are calling the regular java.lang.System.out.println here, but you are not. You are recursively calling your own println method. This call will again call the method, which will again call the method, which will again call the method, ... etc. until you get a StackOverflowError.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!