• Post Reply Bookmark Topic Watch Topic
  • New Topic

what kind of codeis this  RSS feed

 
eugene malcolumn
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we use thhis type of code?



we have nt completed a class yet and mad ean object before..in itself ..what kind of coding style is this?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you do have a complete class already, it just does not do anything besides what it inherits from the primordial java.lang.Object class, which is the ultimate superclass of all classes in Java; the Mother of all Java Classes, so to speak.

The static main method is just a method that Java requires if you are going to run this code directly as a full-blown program.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, that code doesn't compile because Java is case sensitive.

Also, the Sample class si being defined right there. If you don't provided a constructor, a non-argument one is provided for you.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One note:
It seems we're talking here about 2 classes: sample and Sample.
Java is a case sensitive, so you declaring class 'sample' and within its method main() creating an object of another class which is 'Sample'.
Now what this class Sample does we don't know, it must be declared somewhere else and imported before its use or to be declared within the same file, which in that case must be 'sample.java' (edit: not necessarily as 'sample' isn't public)

i.e.:

However, class names following common convention supposed to start with an upper case, just not to confuse yourself and your code reader.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this code couldn't compile because you're missing class's closing curly bracket. Probably code indentation lead to such mistakes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!