• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classes in java

 
Greenhorn
Posts: 10
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why to write everything in class.Can anyone tell me with real life example.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Well, the answer's simple. Java is an object-oriented language, and in a class is the only place it allows you to write code. So you don't need an example to demonstrate that.

If you mean, "why is it designed that way", that's a huge question that we're not going to be able to effectively answer here. I'd suggest reading a tutorial on object-oriented programming to get an idea of how it works.

If you've got some more specific questions we might be able to help you.
 
irrfan jamadar
Greenhorn
Posts: 10
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.But Can I know which tutorial or book you suggest me for understanding this concept like why everything should go into class.what will happen if we will not use class.This question was asked in interview.
 
Ranch Hand
Posts: 343
Mac OS X Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

irrfan jamadar wrote:Thanks for your reply.But Can I know which tutorial or book you suggest me for understanding this concept like why everything should go into class.what will happen if we will not use class.This question was asked in interview.



Hi Irrfan,

In Java everything goes inside a class because it is how it is meant to be so that OOO features can be utilized fruitfully. You will need to go through the OO Concepts. I would recommend you to buy t Head First Object-Oriented Analysis & Design and go through it and all your basics regarding this issue will get resolved. IF you still face issues then come back here and ask your specific questions.
reply
    Bookmark Topic Watch Topic
  • New Topic