GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

Consider the following class definition. public class ExamS…

Consider the following class definition. public class ExamScore { private String studentId; private double score;   public ExamScore(String sid, double s) { studentId = sid; score = s; }   public double getScore() { return score; }   public void bonus(int b) { score += score * b/100.0; } } Assume that the following code segment appears in a class other than ExamScore. ExamScore es = new ExamScore(“12345”, 80.0); es.bonus(5); System.out.println(es.getScore()); What is printed as a result of executing the code segment?

Read Details

A student has created a Car class. The class contains variab…

A student has created a Car class. The class contains variables to represent the following. A String variable called color to represent the color of the car An int variable called year to represent the year the car was made A String variable called make to represent the manufacturer of the car A String variable called model to represent the model of the car The object vehicle will be declared as type Car. Which of the following descriptions is accurate?

Read Details

Consider the following code segment. int num1 = 0; int num2…

Consider the following code segment. int num1 = 0; int num2 = 3; while ((num2 != 0) && ((num1 / num2) >= 0)) {   num1 = num1 + 2;   num2 = num2 – 1; } What are the values of numl and num2 after the while loop completes its execution?

Read Details

Consider the following method. public int mystery(int num) {…

Consider the following method. public int mystery(int num) { int x = num; while (x > 0) { if (x / 10 % 2 == 0) return x; x = x / 10; } return x; } What value is returned as a result of the call mystery(1034) ?

Read Details

Consider the following code segment. int k = 1; while (k < 2...

Consider the following code segment. int k = 1; while (k < 20) {   if ((k % 3) == 1)     System.out.print(k + " ");     k++; }   What is printed as a result of executing this code segment?

Read Details

Consider the following two code segments. Code segment II is…

Consider the following two code segments. Code segment II is a revision of code segment I in which the loop header has been changed. I. for (int k = 1; k = 1; k–) { System.out.print(k); } Which of the following best explains how the output changes from code segment I to code segment II?

Read Details

Consider the following method. public String wordPlay(Strin…

Consider the following method. public String wordPlay(String word) { String str = “”; for (int k = 0; k < word.length(); k++) { if (k % 3 == 0) { str = word.substring(k, k + 1) + str; } } return str; } The following code segment appears in another method in the same class as wordPlay. System.out.println(wordPlay("Computer Science")); What is printed as a result of executing the code segment?

Read Details

Consider the following method. public static String changeS…

Consider the following method. public static String changeStr(String str) { String result = “”; for (int i = str.length() – 1; i >= str.length() / 2; i -= 2) { result += str.substring(i, i + 1); } return result; } What value is returned as a result of the method call changeStr(“12345”) ?

Read Details

Consider the following code segment. int j = 1; while (j <...

Consider the following code segment. int j = 1; while (j < 5) { int k = 1; while (k < 5) { System.out.println(k); k++; } j++; } Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?

Read Details

A bear is an animal and a zoo contains many animals, includi…

A bear is an animal and a zoo contains many animals, including bears. Three classes Animal, Bear, and Zoo are declared to represent animal, bear, and zoo objects. Which of the following is the most appropriate set of declarations? A public class Animal extends Bear {   … } public class Zoo {   private Animal[] myAnimals;   … } B public class Bear extends Animal {   … } public class Zoo {   private Animal[] myAnimals;   … } C public class Animal extends Zoo {   private Bear myBear;   … } D public class Bear extends Animal, Zoo {   … } E public class Bear extends Animal implements Zoo {   … }

Read Details

Posts pagination

Newer posts 1 … 45,855 45,856 45,857 45,858 45,859 … 76,003 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top