This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me on this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help me on this "constructor" question!" Watch "Help me on this "constructor" question!" New topic

Help me on this "constructor" question!

Ben Gao

Joined: Feb 19, 2002
Posts: 8
Determine the result of attempting to compile and run the following code:
class A {
public int Avar;
public A() {
public void doSomething() {
Avar = 1111;
public class B extends A {
public int Bvar = 2222;
public B() {

public void doSomething() {
System.out.println("Bvar=" + Bvar);
public static void main(String[] args) {
new B();
The output is:

My questions are:
why "A.doSomething()" is not output?
Why "Bvar=0"?

Thank you!
Jennifer Wallace
Ranch Hand

Joined: Nov 30, 2001
Posts: 102
This discussion deals with the same
[ February 19, 2002: Message edited by: Jennifer Wallace ]
[ February 19, 2002: Message edited by: Jennifer Wallace ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!

I agree. Here's the link:
subject: Help me on this "constructor" question!