Menu
Topics Index
...
`

Creating Abstract class and its implementation


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Abstract class and its implementation
What will be the output of the following program?
public class Cards {
    public static void main(String[] args) {
        final Card[] allCards = new Card[3];
        allCards[0] = new WeddingCard();
        allCards[1] = new GreetingCard();
        allCards[2] = new Card() {
            String getDateAndLocation() {
                date = allCards[1].location;
                location = allCards[0].date;
                return super.getDateAndLocation();
            }
        };
        for (Card card : allCards) {
            card.date = "30/02/2015";
            card.location = "Bangalore";
            System.out.print(card.getDateAndLocation() + " ");
        }
    }
}
abstract class Card {
    String date = "06/11/1990";
    String location = "Anantapuram";
    String getDateAndLocation() {
        return date + "~" + location;
    }
}
class WeddingCard extends Card {
    String date = "23/04/2015";
    String getDateAndLocation() {
        return date + "~" + location;
    }
}
class GreetingCard extends Card {
    String location = "Hyderabad";
    String getDateAndLocation() {
        return date + "~" + location;
    }
}

A. 23/04/2015~Bangalore 30/02/2015~Bangalore Bangalore~30/02/2015
B. 30/02/2015~Bangalore 30/02/2015~Bangalore Bangalore~30/02/2015
C. 30/02/2015~Bangalore 30/02/2015~Hyderabad Bangalore~30/02/2015
D. 23/04/2015~Bangalore 30/02/2015~Hyderabad Bangalore~30/02/2015
E. Some other output
F. Compilation Error or Runtime Error
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is d..in GreetingCard wil return location as hyd date as 23 it wl use in cards class varble date sam fo wedding card also and last we are printing the Cards class details

Posted by Uday Kumar    2014-08-13 12:50:04


Congratulations Uday Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-14 04:13:26


© meritcampus 2019

All Rights Reserved.

Open In App