The moose likes Java in General and the fly likes can class name and method name be same? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "can class name and method name be same?" Watch "can class name and method name be same?" New topic
Author

can class name and method name be same?

Mohan Mehra
Ranch Hand

Joined: Jul 28, 2011
Posts: 60
i have a class called FilterTraps . can i have a method called filterTraps in it? is it according to java code conventions. please say yes or no. don't give me java code conventions document
Michael Dunn
Rancher

Joined: Jun 09, 2003
Posts: 4041
> i have a class called FilterTraps . can i have a method called filterTraps in it?

what happened when you tried it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

In that example, you used different names. Remember that Java is case-sensitive.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Here's some code to confuse you and, ofcourse, to learn from. Can you explain what the different JavaRanches in this code mean?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3143
Mohan Mehra wrote:please say yes or no. don't give me java code conventions document


That's a really bad attitude. It's far better to point you at the appropriate documentation and let you do some research on your own than to just hand you an answer.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 2687

Note that while Jesper's example "works", it does break Java conventions because it uses a method and a variable starting with an upper-case letter. Which shows there's a difference between what you can do and what you should do. The compiler doesn't try and enforce convention.

Your initial example doesn't break the convention because you've got the cases right. Someone who's used to the conventions will be able to tell the difference easily. Whether it's a good idea depends on whether "FilterTraps" is a good name for the class and the method. I'm a bit doubtful, but it depends on what they do - it might be perfectly sensible.
 
 
subject: can class name and method name be same?
 
Threads others viewed
NX:Java Convention Style- Comments
help me,about DataInputStream
Help debugging code
Some very basic Java questions
java.util.array not recognised
IntelliJ Java IDE