Top Posters
Since Sunday
L
4
d
4
3
k
3
k
3
j
3
k
3
b
3
f
3
b
3
d
3
h
3
New Topic  
temp321 temp321
wrote...
Posts: 493
4 years ago
Analyze the following code:

public class Test extends A {
public static void main(String[] args) {
Test t = new Test();
t.print();
}
}

class A {
String s;

A(String s) {
this.s = s;
}

public void print() {
System.out.println(s);
}
}


▸ The program does not compile because Test does not have a default constructor Test().

▸ The program compiles, but it has a runtime error due to the conflict on the method name print.

▸ The program would compile if a default constructor A(){ } is added to class A explicitly.

▸ The program has an implicit default constructor Test(), but it cannot be compiled, because its super class does not have a default constructor. The program would compile if the constructor in the class A were removed.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 30 times
1 Reply
Replies
Answer verified by a subject expert
Brittany08196Brittany08196
wrote...
Posts: 368
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here

Related Topics

temp321 Author
wrote...

4 years ago
Thanks
wrote...

Yesterday
You make an excellent tutor!
wrote...

2 hours ago
This calls for a celebration Person Raising Both Hands in Celebration
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1155 People Browsing
Related Images
  
 42
  
 336
  
 299
Your Opinion
Which industry do you think artificial intelligence (AI) will impact the most?
Votes: 405

Previous poll results: Who's your favorite biologist?