File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes kathy sierra scjp 1.6 book question  doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "kathy sierra scjp 1.6 book question  doubt" Watch "kathy sierra scjp 1.6 book question  doubt" New topic

kathy sierra scjp 1.6 book question doubt

dilip kumarr

Joined: Jan 31, 2010
Posts: 6

what is the result?

class Top {
public Top(string s)
public class Bottom2 extends Top{
public Bottom2(String s)
public static void main(String [] args){
new Bottom2("c");
System.out.println(" ");

1.wats the meaning of : new Bottom2("c"); in the above program.

kindly clear my doubt...........

thanks in advance..............

Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

it means you are calling the overloaded constructor of Bottom2 class.

SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Shailesh Phatak
Ranch Hand

Joined: Aug 27, 2009
Posts: 64
since the base class does not have an explicit zero arg contructor it will produce an error

See Dreams With Open Eyes And Make It Real
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

by the way there are some errors in your code...
Nur Ahmed

Joined: Mar 10, 2010
Posts: 1
I think M M kaimkhani already gave you the answer in his first response.

new Bottom2("c") is the call to the constructor Bottom2 which has an implicit call to the super (not visible in this piece of code though. you have to code it in as if you have a constructor with arguments the compiler will not provide you a similar one or a default one). //using braces in java is tricky ... :-) all I meant is, for the minimum, you will need to add something like super(""); in the Bottom2 constructor.

So, to sum up, the logic/catch is to call the super class constructor first. Try running the code without "new Bottom2("c")" ;-)

Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 39
First of all code is wrong
1- There is } closing bracket is missing.
2- There is no no-arg constructor is in Top class.

So Code will fail ...

SCJP 6.0
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

Dilip please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: kathy sierra scjp 1.6 book question doubt
It's not a secret anymore!