• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic