Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. (10 pts) What is wrong with the following code? How should it be fixed? 1 public class H2ClassG { 2 final int x; 3

6. (10 pts) What is wrong with the following code? How should it be fixed?

1 public class H2ClassG { 2 final int x; 3 4 H2ClassG () {} 5 H2ClassG (int a) {x = a;} 6 } // end class H2ClassG

7. (10 pts) What is wrong with the following code? How should it be fixed?

1 public class H2ClassH { 2 final int x; 3 4 int H2ClassH () { 5 if (x == 7) return 1; 6 return 2; 7 } // end 8 } // end class H2ClassH

8. (10 pts) What is wrong with the following code? x should be given a value of 24. What are two ways this can be legally accomplished?

1 public class H2ClassI { 2 final int x; 3 4 public static void main (String args []) { 5 H2ClassI h = new H2ClassI (); 6 h.x = 24; 7 } // end main 8 } // end class H2ClassI

9. (10 pts) What is wrong with the following code? Give two effective ways to fix it.

1 import javax.swing.*; 2 import java.awt.event.*; 3 4 public class H2ClassJ extends JFrame { 5 public static final long serialVersionUID = 22; 6 7 public H2ClassJ () { 8 addMouseListener (new MouseListener () { 9 public void mouseClicked (MouseEvent e) {} 10 }); 11 } // end constructor 12 13 } // end class H2ClassJ

10. (10 pts) Why does the following code give a compiler warning? (Use javac -Xlint) How should it be fixed?

1 import javax.swing.*; 2 3 public class H2ClassK { 4 String [] sa = {"a", "b", "c"}; 5 JComboBox jcbA = new JComboBox (sa); 6 } // end class H2ClassK

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions