Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class definition in Java vs C++  RSS feed

 
ken delsignore
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am a long time C++ programmer and recently have begun using Java. In the Java code I have seen, the class definitions have all of the member function code inside the class definition. This makes it more difficult compared to C++, where you can read the class definition without the code. Can Java be written the same way?
thanks
Ken
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the javadoc program (part of the JDK). It may generate something in the format you are looking for.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ken delsignore wrote:This makes it more difficult compared to C++, where you can read the class definition without the code. Can Java be written the same way?

Well, you can write interfaces; or cooperative classes if it makes sense. But no, there's no specific way to separate methods from their code. Methods are either abstract (no code), or they contain code.

You can create "stubs", as outlined here - but this is usually done as a preliminary step to implementation.

Winston
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh, I seem to remember thinking something along the same lines when I transitioned from C++ to Java back in 1998. I got used to it pretty quickly.
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!