Writing Classes Quiz CodeHS

Posted on

Writing Classes Quiz is the name of the quiz that was created by jram[ersaud02. This one was shared on Quizlet. At the time of writing, it has a 5.0 rating with 7 reviews. Apparently, the quiz consists of a total of 20 terms. Below are the terms included in this set:

  1. Term: Given this code snippet, public class Person {public string name; public Person(String name) {this name = name; } public void changeName(String name) {this.name – name; } public void printName() { System.out.printIn(this.name); } }
    What will this code print? Person myPerson = new Person(“Bob”); myPerson.changeName(“Joe”); myPerson name = “John”; myPerson.printName();
    Description: John
  2. Term: Given this code snippet, public class Athlete {public Athlete(String name) {this.name = name; } }
    Description: Need to declare the name instance variable
  3. Term: public class Pokemon {private String name; private int health; public Pokemon(String name, int health) {name = name; health = health; } }
    what is wrong with the class definition? Hint: We expect the instance variables name and health to be initialized in the constructor.
    Description: Must use this in constructor when the constructor parameters have the same name as instance variables. ie: this.name = name; this.health = health;
  4. Term: Public class Main {private static int n = 0; public static void bar() { Main m1 = new Main(); Main m2 = new Main(); Main m3 = new Main(); m1.foo(); } public Main() { n = n + 1; } public void foo() {System.out.printIn(n); } }
    Description: 3
  5. Term: What should be the output of the program if bar() were changed to the following:
    public static void bar() {Main m1 = new Main(); Main m2 = new Main(); Main m3 = new Main(); m1.setN(5); m3.foo(); }
    Description: 5
  6. Term: public class Main {private String str = “bar”; public void run() {Main m = new Main m = new Main(“foo”); System.out.printIn(m.getString()); } public Main(String str) { str = str; } public String getString() {return str; } }
    Description: bar
  7. Term: public class athlete {private String first_name; private String last_name; private int jersey; public int getJersey() {return this.jersey; }
    public Athlete(string first_name, String last_name, int jersey) { this.first_name = first_name; this.last_name = last_name; this.jersey = jersey; } }
    Description: You cannot set the jersey, since jersey is private and there is no setter method.
  8. Term: public class Athlete {private String first_name; private String last_name; private int jersey; public int getJersey() { return this.jersey; }
    public Athlete(string first_name, String last_name, int jersey) {this.first_name = first_name; this.last_name = last_name; this.jersey = jersey; } }
    Description: atlete.getJersey()
  9. Term: public class Athlete {private String first_name; private String last_name; private int jersey; public int getJersey; }
    public Athlete(string first_name, String last_name, int jersey) { this.first_name = first_name; this.last_name = last_name; this.jersey = jersey; } }
    Description: public void setJersey (int jersey) { this.jersey = jersey; }
  10. Term: public class Athlete { String first_name; String last_name; int jersey; public Athlete(String first_name, String last_name, int jersey) { this.first_name = first name; this.last_name = last_name; this.jersey = jersey; } }
    Description: Athlete athlete = new Athlete(“Dirk”, “Nowitzki”, 41);
  11. Term: public class Foo { int bar; String stoo; public Foo() { this.bar = 0; this.stoo = “”; } public Foo(int bar) { this.bar = bar; stoo = “You”; }
    Description: Foo fee; fee = new Foo();
  12. Term: Which of the following are valid instantiations of the class Athlete? I – Athlete joe = new Athlete(“Joe”, “Montana); II – Athlete joe = new Athlete(“Joe, “Montana”, “16”); III – athlete joe = new Athlete(“Joe”, “Montana”, 16);
    Description: I and III
  13. Term: public class Foo { public static void foo() { … } public void bar() { … } public void baz() {
    Description: foo()
  14. Term: public class Tvshow { private String name; private int channel; public TvShow (string name, int channel) { this.name = name; this.channel = channel; } public void getName() { return name; } public void setName(String name) { this.name = name; } }
    Description: The return type for the getName method should be set to String.
  15. Term: public class Strom { private int lighteningCount, private int precipTotal; private String precipType; public Storm(string precipType) { this.precipType = preciptType; precipTotal = 0; lighteningCount = 0; }
    public Strom(String precipType, int precipTotal) { this.precipType = precipType; this.precipTotal = precipTotal; lighteningCount = 0; }
    public Storm(String precipType, int lighteningCount) { this.precipType = precipType; this.lighteningCount = lighteningCount; precipTotal = 0; } }
    Description: The code will not compile because there are two constructors with the same signature.
  16. Term: Which of the following would be the best example of how the Internet has impacted the economy?
    Description: Email has reduced the amount of mail that is produced and shipped.
  17. Term: Which of the following is not part of the ACM Code of Ethics and Professional Conduct’s General Ethical Principles?
    Description: Credit original creator when using other’s work.
  18. Term: public static String mystery(String word, int I, int j) { string mystery = word.substring(I, i+ 1); mystery += word.substring(I, j); return mystery; }
    Description: Precondition: I >= 0, I < word.length, I < = j.
  19. Term: public static String mystery(string word, int I, int j) { string mystery = word.substring(I, i+ 1); mystery += word.substring(I, j); return mystery; }
    Description: Precondition: j >= I and j <= word.length.
  20. Term: The Insect class will contain a String for the insect’s name, an int for the number of legs it has, and a Boolean for whether or not the insect has wings. Which of the following is the most appropriate implementation for the Insect Class?
    Description: public class Insect { private String name; [private int numLegs; private Boolean hasWings; //constructor and methods not shown }

For more information about the Writing Classes Quiz by jrampersaud02, you are recommended to go to the official website of Quizlet. Make sure to log in to your account to get full access. If you do not have an account, you can just log in by using your email.

Leave a Reply

Your email address will not be published.