Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:20:48+00:00 2026-06-15T20:20:48+00:00

I am continuing to study from the e-book An introduction to Java Programming. In

  • 0

I am continuing to study from the e-book “An introduction to Java Programming”. In that e-book, I use this method:

/**
 * This method scans the array of cards in a for loop.
 */
public void getDetialsOfCards() {
    // Declare a local variable.
    MembershipCard card = null;

    // note the use of the instanceof operator
    for (int i = 0; i < noOfCards; i++) {
        if (cards[i] instanceof DvdMembershipCard) {
            card = cards[i];
            System.out.println("This is a DVD card with " + getNoOnLoan()
                    + " DVDs currently on loan.");

        } else if (cards[i] instanceof GameMembershipCard) {

            card = cards[i];
            System.out.println("This is a games card with " +
                    getNoOnLoan() + " CDs currently on loan");

        } else {
            System.out.println("Neither type of card.");

        }
    } // End of for loop.

}

Here is my main method:

public class CompundIfElsegetDetialsOfCards {

    // private static int noOfCards = 2;
    private static int NoOnLoan;
    private static Object[] cards;

    private static DvdMembershipCard[] dvd = new DvdMembershipCard[6];
    private static GameMembershipCard[] game = new GameMembershipCard[6];
    private static MembershipCard card;

    public static void getDetialsOfCards() {
        // Declare a local variable.

        int noOfCards = 6;

        // note the use of the instanceof operator
        for (int i = 0; i < noOfCards; i++) {
            if (cards[i] instanceof DvdMembershipCard) {
                card.equals(cards[i]);

                System.out.println("This is a DVD card with " + getNoOnLoan()
                        + " DVDs currently on loan.");

            } else if (cards[i] instanceof GameMembershipCard) {
                card.equals(cards[i]);

                System.out.println("This is a games card with " +
                        getNoOnLoan() + " CDs currently on loan");

            } else {
                System.out.println("Neither type of card.");

            }

        } // End of for loop.

    }

    public static void main(String[] args) {
        CompundIfElsegetDetialsOfCards.getDetialsOfCards();
    }

    private static int getNoOnLoan() {

        System.out.println("jumlah Loan ");
        return NoOnLoan;
    }

    private static class MembershipCard {

        public MembershipCard() {

        }
    }

    private int i;

    private static class DvdMembershipCard {
        public DvdMembershipCard() {

        }
    }

    private static class GameMembershipCard {
        public GameMembershipCard() {

        }
    }
}

The code compiles successfully but there is no output. What I must add to solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:20:49+00:00Added an answer on June 15, 2026 at 8:20 pm

    Are you sure you are not receiving any exceptions.

    You will receive java.lang.NullPointerException in the below line

    if (cards[i] instanceof DvdMembershipCard)
    

    You have not assigned any object to static Object[] cards; parameter you will receive the Null pointer exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is continuing on from a query that was solved previously via stackoverflow (
Continuing from this question : When I am trying to do fopen on Windows,
Continuing on from this question here: Forum data in mysql database What would be
Continuing from my previous question , is there a comprehensive document that lists all
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
Continuing from the question that I asked here: C++ multi-dimensional data handling In my
Continuing on from this question programmatically creating a drop down list I would like
Continuing from this question, I've got a form with all the Vehicles listed for
Continuing from this thread: What are good algorithms for vehicle license plate detection? I've
Continuing from Stack Overflow question Java program to get the current date without timestamp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.