Skip to main content

Java Trick for All...

Posted by awaisbajwa on January 12, 2007 at 6:14 PM PST

I have two classes .... Class A

public abstract class A {
int a = 8;
public A() {
abstract void show();

And following is a class Trick extending class A.

public class Trick extends A{
int a = 90;
void show(){
"value of a is " + a);
public static void main(String args[]){
new Trick();

What is the output of the main method of class Trick ??? try it out and then answer ....stop here and try it out.

yes you are right .... the output is 0

As, at the time of object data member initialization the value is by defualt zero for integer, and the no-arg constructor of class Trick calles the no-arg constructor of class A that has value of a == 0 going down.

Are you thinking in Java?

Related Topics >>