What is happening in the program?

Hi friends,
i was going through this program, and i could not understand why its not printing anything.
class A {
     String str1 = "";
     String str2 = "";
     String getA() {
          return str1;
     void setA(String s) {
          str1 = s;
     String getB() {
          return str2;
     void setB(String s1) {
          str2 = s1;
class B extends A{
public class N {
     public static void main(String a[]) {
          A aobj = new A();
          A aobj1 = new B();
          aobj.setA("Sun");
                aobj.setB("Java");
          aobj1.getA();
          System.out.println(aobj1.getA());
}

I think you may have a typo.
You are calling setter methods on aobj:
  aobj.setA("Sun");
  aobj.setB("Java");And then calling a getter method on aobj1:
System.out.println(aobj1.getA());aobj and aobj1 are different objects. You never call a setter method for aobj1, so its member attributes are still initialised to empty strings...
Cheers, Neil

Similar Messages

Maybe you are looking for

  • Key Figure units in Fact Table - Error

    All - When a run a report off of a cube, some row display 0 when there are corresponding values in my cube.  The report doesn't agree with LISTCUBE.  I have ran transaction RSRV on my cube and tested the "Key figure units in fact tables of Infocube"

  • Need to author DVD from FCP X

    I converted to FCP X and need to author DVDs from the footage I shot.  Since I still have DVD Studio Pro I imported the footage, authored the DVD and burned it. It won't play on my DVD player, Blu Ray player or even my Mac. In the build I get notes t

  • Computer freezes after software install

    after i updated to the newest version of snow leapord my computer will freeze/and or restart during use. also, i now cannot access my system prefereces. what does all of this mean?

  • HOw to make AE render my imported sound?

    I imported a sound and layered it in the comp but AE doesnt render it in preview nor in final movie. It says that the sound option is set to off in the render settings but i see no where i can change that. What can i do?

  • Funds Management - Reconstruct payment data

    Hello, I have implement Funds Management with Multi-Year Budget Execution and update profile 00101 (posting date) and realize that my commitment item for vendor account was 40 and not 60 so I have some invoices that are not updated with the payment i