• 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

whether Object is a keyword?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Object {

String str ;

Object ( String str ) {
this . str = str ;
}

public String toString ( ) {
return str ;
}
};

class Ques extends Object{

Ques ( String str ) {
super ( str ) ;
}

public static void main ( String args [ ] ) {
Ques x = new Ques ( " My Object " ) ;
System . out .println ( x. str ) ;
}
};

in this prg, the class is named as Object. my doubt is when Object is a class, how could we use 'Object' as a class name in our prg?please explain..
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you put it in a package other than java.lang, then it'll work perfectly fine Just whenever you want to refer to the one-and-only Object from Java API, you would have to write java.lang.Object
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object is a class not a keyword. It is ok to write classes whose names are the same as java system classes. Just make sure you know which class you are using . For exam java.util.Date and java.sql.Date may be used within the same class. You just have to mention the full package name when you want to specifically use one of them.
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dariusz and Deepak.. i ve understood on your reply..
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dariusz and Deepak.. i ve understood on your reply..
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Object
{
public static void main( String args [] )
{
System . out .println ("hello") ;
}
}

i created this file in default package , it is compiling file and also printing "hello"? why
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi varinder..
this is what deepak has told us.
'It is ok to write classes whose names are the same as java system classes'
Say if we want to use system classes, we have to mention the full package name when we want to specifically use one of them'
so your code compiled and gave the output.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic