Question

Analyze the following code in these 2 Java classes and choose the correct statement below: public...

Analyze the following code in these 2 Java classes and choose the correct statement below:

public class Test
{
public static void main(String[] args)
{
Time1 time = new Time1();
time.print();
}
}

public class Time1
{
   private String showTime;

   public Time1(String newTime)
{
showTime = newTime;
}

   public void print()
{
System.out.printf("%s", showTime);
}
}

a.

The program will compile and run if you change:
Time1 time = new Time1();  → Time1 time = new Time1("5:15");

b.

The program causes a compilation error because class Time1 is not a public class.

c.

The program causes a compilation error because class Time1 is missing a no-arg constructor.

d.

The program compiles and runs fine but prints nothing.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer:

The program causes a compilation error because class Time1 is missing a no-arg constructor.

Add a comment
Know the answer?
Add Answer to:
Analyze the following code in these 2 Java classes and choose the correct statement below: public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • class Test public static void main(String args) { Aa=new AO: a.printo: class A private String s;...

    class Test public static void main(String args) { Aa=new AO: a.printo: class A private String s; public A (String news) { 8 = news: public void print { System.out.println(s): The program would compile and run if you change A a new Alto Aa=new A('5'). The program has a compilation error because the instance variables in class A is not public. The program has a compilation error because class A does not have a no-arguments constructor The program compiles and runs...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Analyze the following code: public class Test { public int x; public Test(String t) { System.out.println("Test");...

    Analyze the following code: public class Test { public int x; public Test(String t) { System.out.println("Test"); public static void main(String[] args) { Test test: System.out.println(test.x); The program has a compile error because Test class does not have a default constructor The program has a compile error because test is not initialized OO The program has a compile error because x has not been initialized The program has a runtime NullPointerException while executing test.x because test is a null reference and...

  • Analyze the following code: public class Test { private int t; public static void main(String[] args)...

    Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } t is non-static and it cannot be referenced in a static context in the main method. The program compiles and runs fine. The variable t is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.

  • Analyze the following code: public class Test { private int t; public static void main(String[] args)...

    Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } The variable t is private and therefore cannot be accessed in the main method. The program compiles and runs fine. t is non-static and it cannot be referenced in a static context in the main method. The variablet is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.

  • Java questions QUESTION 8 Assume the following classes are each defined in their own java files...

    Java questions QUESTION 8 Assume the following classes are each defined in their own java files and compile public class A public void display { System.out.println("A's display"); public class B extends A{ public void display { System.out.println("B's display"); public class C extends A public void display { System.out.println("C's display"); public class D { public static void main(String args) { 3: int i = ((int)(Moth.random(* 10)) if (i == 0) a = new BO: else if (i == 1) a =...

  • Analyze the following code: class Test ( private int t static int x; public void method()...

    Analyze the following code: class Test ( private int t static int x; public void method() Test test new Test); System.out.println (x); a. The variable t is not initialized and therefore causes er The program compiles fine but has runtime errors because main method. cThe variable t is private and therefore cannot be accessed in t method. The program compiles and runs fine

  • What is printed from the following program? 1 class Sophie { 2    3 public static...

    What is printed from the following program? 1 class Sophie { 2    3 public static void main(String[] args) { 4 5 String s = "Java"; 6 StringBuilder buffer = new StringBuilder(s); 7 change(buffer); 8 System.out.println(buffer); 9 } 10 11 public static void change(StringBuilder sbval) { 12 sbval.append(" and HTML"); 13 } 14 15 } 16 17    Java and HTML Nothing. There is a runtime error on line 12 The program will not compile Java

  • This is a question about Java abstract classes. The correct answer is E and I do...

    This is a question about Java abstract classes. The correct answer is E and I do not understand why. Please be specific! I am a beginner in Java abstract classes and methods... 13.6 What is the output of running class Test? public class Test {   public static void main(String[] args) {     new Circle9();   } } public abstract class GeometricObject {   protected GeometricObject() {     System.out.print("A");   }   protected GeometricObject(String color, boolean filled) {     System.out.print("B");   } } public class Circle9 extends GeometricObject {...

  • What is the output of running class C? The three Java classes are in separate Java...

    What is the output of running class C? The three Java classes are in separate Java files in the same directory (or in the same package). class A { public AO { System.out.println("The default constructor of A"); } // end A constructor } // end class A class B extends A { public BCString s) { System.out.println(s); } // end B constructor } // end class B public class C { public static void main(String[] args) { B b =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT