Test: Computer Science

Consider the following code:

private static class Philosopher {

        private String name;

        private String favoriteSubject;     

        public Philosopher(String n, String f) {

                name = n;

                favoriteSubject = f;

        }       

        public String getName() {

                return name;

        }       

        public String getFavoriteSubject() {

                return favoriteSubject;

        }      

        public void speak() {

                System.out.println("Hello, World!  My name is "+name + ".  My favorite subject is "+favoriteSubject);

        }

}

private static class Nominalist extends Philosopher {

        boolean franciscan;     

        public Nominalist(String n,boolean frank) {

                super(n,"logic");

                franciscan = frank;

        }      

        public void speak() {

                super.speak();

                if(franciscan) {

                        System.out.println("I am a Franciscan");

                } else {

                        System.out.println("I am not a Franciscan");

                }

        }   

        public String whoMightHaveTaughtMe() {

                if(franciscan) {

                        return "Perhaps William of Ockham?....";

                } else {

                        return "Perhaps it was Durandus of St. Pourçain — scandalous, a Dominican nominalist!";

                }

        }

public static void main(String[] args) {

     Philosopher[] phils = {

               new Philosopher("Petrus","Ethics"),

               new Nominalist("Minimus Maximus",false),

               new Nominalist("Theodoric",true)};

     for(int i = 0; i < phils.length; i++) {

          phils[i].speak();

     }

}

1.

What is the output for the code above?

Hello, World!  My name is Minimus Maximus.  My favorite subject is logic. I am not a Franciscan

Hello, World!  My name is Petrus.  My favorite subject is Ethics

Hello, World!  My name is Theodoric.  My favorite subject is logic. I am a Franciscan

Hello, World!  My name is Petrus.  My favorite subject is Ethics

Hello, World!  My name is Minimus Maximus.  My favorite subject is logic

Hello, World!  My name is Theodoric.  My favorite subject is logic

Hello, World!  My name is Petrus.  My favorite subject is Ethics

Hello, World!  My name is Minimus Maximus.  My favorite subject is logic I am not a Franciscan

Hello, World!  My name is Theodoric.  My favorite subject is logic I am a Franciscan

Hello, World!  My name is Petrus. My favorite subject is Ethics

Hello, World!  My name is Minimus Maximus. My favorite subject is logic

I am not a Franciscan

Hello, World!  My name is Theodoric.  My favorite subject is logic

I am a Franciscan

Hello, World!  My name is Petrus.  My favorite subject is Ethics

Hello, World!  My name is Minimus Maximus.  My favorite subject is logic

Hello, World!  My name is Theodoric.  My favorite subject is logic

1/4 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors