This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Object

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does compiler give error, if we say implicitly, a class extends Object though it is default ?
public class Base extends Object { }
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try it and see if it compiles. It's a great way to find out this sort of thing.
[This message has been edited by Jim Yingst (edited February 12, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did so....Jim, but related question as follows. Help me get into that.
<PRE>
public class Base extends Object { //line 1
String objType;
public Base() { objType = "I am a Base type";
}
}
public class Derived extends Base { //line 2
public Derieved() { objType = "I am Derived type";
}
public static void main(String args{}) {
Derived D = new Derived();
}
}
</PRE>
A)Two class files, Base,class and Derived.class will be created.
B)The compiler will object to line 1..........(Answer)
C)The compiler will object to line 7.
My question is the same why answer is B ?

[This message has been edited by Umesh (edited February 13, 2000).]
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is simple: You can't have two public classes in a compilation unit (ie .java file).
There are other errors (is it typos?): It should be,
public static void main(String args[]) {
and name of constructor: Derived.
[This message has been edited by Thandapani Saravanan (edited February 13, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Thandapani for correcting my vision and typos!!!
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, if you read the questions (which you did not post) it says "The following lists the complete contents of the file named Derived.java:
The compiler objects to line 1 because the name of the first public class is "Base". Needs to be "Derived".
I could not figure this out until I read the answer. Hope this helps.
Frank
reply
    Bookmark Topic Watch Topic
  • New Topic