Does each of the following programs compile and run? If no, explain the reason; otherwise, give...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Does each of the following programs compile and run? If no, explain the reason; otherwise, give the output. 1. class P1 { } } public static void main(String[] args) { A b = new B(); B a = b; a.show(); b.show(); class A { } } public String str="A"; public void show () { } class B extends A { System.out.println(str); public String str = "B"; public void show () { } System.out.println(str); 2. class P2 { } } public static void main(String[] args) { A o = new B(); o.m(); class A { } } char x = 'a'; public char getX() { return x; } public void m () { } class B extends A { char x = 'b'; System.out.println (getX()); public void m() { } System.out.println (getX()); 3. import java.util.*; class P3 { } ArrayList<Object> 1st; } public void add (Object obj) { if (!1st.contains (obj)) 1st.add(obj); } public static void main(String[] args) { P3 d = new P3(); d. add (1); d. add (1); d. add (2); d. add (2); 4. class P4 { } public static void main(String[] args) { try { } int value = 1; if (value 0.0 > 0) System.out.println("true"); } catch (Exception ex) { } System.out.println (ex.getMessage()); System.out.println("Continue after the catch block"); 5. import java.util.Scanner; class P5 { public static void main(String[] args) { Scanner input = new Scanner ("abc 123"); try { int i = input.nextInt (); } } } catch (Exception ex) { System.out.println("A"); } finally { } System.out.println("B"); Does each of the following programs compile and run? If no, explain the reason; otherwise, give the output. 1. class P1 { } } public static void main(String[] args) { A b = new B(); B a = b; a.show(); b.show(); class A { } } public String str="A"; public void show () { } class B extends A { System.out.println(str); public String str = "B"; public void show () { } System.out.println(str); 2. class P2 { } } public static void main(String[] args) { A o = new B(); o.m(); class A { } } char x = 'a'; public char getX() { return x; } public void m () { } class B extends A { char x = 'b'; System.out.println (getX()); public void m() { } System.out.println (getX()); 3. import java.util.*; class P3 { } ArrayList<Object> 1st; } public void add (Object obj) { if (!1st.contains (obj)) 1st.add(obj); } public static void main(String[] args) { P3 d = new P3(); d. add (1); d. add (1); d. add (2); d. add (2); 4. class P4 { } public static void main(String[] args) { try { } int value = 1; if (value 0.0 > 0) System.out.println("true"); } catch (Exception ex) { } System.out.println (ex.getMessage()); System.out.println("Continue after the catch block"); 5. import java.util.Scanner; class P5 { public static void main(String[] args) { Scanner input = new Scanner ("abc 123"); try { int i = input.nextInt (); } } } catch (Exception ex) { System.out.println("A"); } finally { } System.out.println("B");
Expert Answer:
Answer rating: 100% (QA)
The images youve provided contain Java code snippets for different classes P1 P2 P3 P4 P5 with a question regarding their compilation and execution st... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
How do you simplify the max method in the following, using the conditional operator? 1: /** Return the max of two numbers */ 2: public static int max ( int num1, int num2 ) { 3: int result; 4: 5: if...
-
The net present value and internal rate of return desirability measures for two mutually exclusive investments being considered by Stockton Corporation to follow. Year NPV IRR R 161 14.60% S 138...
-
White Company has two departments, Cutting and Finishing. The company uses a job-order costing system and computes a predetermined overhead rate in each department. The Cutting Department bases its...
-
Calculation practice: Confidence interval for variance. Refer to Practice Problem 1. Using the data, calculate the 95% confidence interval for the variance with the following steps. a. What does the...
-
Explain the working of constant volume combustion gas turbine.
-
Bird-Bath, Inc., experienced four situations for its supplies. Compute the amounts that have been left blank for each situation. For situations 1 and 2, journalize the needed transaction. Consider...
-
Explain the Six attitudes/assumptions of Experimental Analysis of Behavior and the Seven Dimensions of Applied Behavior Analysis and examine how they contribute to the development of a technology...
-
Tax Software Assignment - Fall 2023 Ms. Jeanette Letourneau (SIN 123-456-789) was born in Montreal on December 15, 1979. She has spent most of her working life a song writer but also has a part-time...
-
A teacher traces a small circle on the palm of a kindergartener's hand to let him know it is time for free play. What type of disability does this child most likely have? A. Traumatic Brain Injury B....
-
If internal controls are ineffective, what wouldbe the most thorough means of evaluating the effectiveness of internal controls is by performing internal audits? What are internal audits are and...
-
A company reports the following: Cost of merchandise sold Average merchandise inventory $680,400 94,500 Determine (a) the inventory turnover and (b) the number of days' sales in inventory. Round...
-
The following trial balance of Teal Mountain Co. does not balance. Teal Mountain Co. Trial Balance June 30, 2022 Debit Credit Cash $1,660 Accounts Receivable $2,440 Supplies 1,200 Equipment 2,300...
-
All transactions must require a passkey The balance of the account is zero and all outstanding cheques have been presented The system cannot accept a transaction that results in a debit balance...
-
Working capital = Current assets - current liabilities= 2,790,000 Working capital Current Ratio current = assets/current liabilities = 4.1 Accounts receivable turnover = sales/acc receivable =...
-
Q3: what is the velocity of 30 Kg weight after the xx Kg weight has fallen 15 m. Note the whole system was released from rest and xx is last two numbers of your ID. 30 Kg xx Kg
-
The water in tank A is at 270 F with quality of 10% and mass 1 lbm. It is connected to a piston/cylinder holding constant pressure of 40 psia initially with 1 lbm water at 700 F. The valve is opened,...
-
The Fibonacci sequence is a sequence of numbers in which the first two numbers are 1 and each subsequent number is the sum of the previous two Fibonacci numbers. The sequence is 1, 1, 2, 3, 5, 8, 13,...
-
What are some advantages of creating an IntList interface and having both types of lists implement it?
-
Write a method called indexOfSubList that accepts another list L as a parameter and returns the starting index of where L first appears in this list, or -1 if it is not found. All elements of L must...
-
Wallace and Hussain type estimators for the variance components of a one-way unbalanced panel data model. (a) Verify the \(E\left(\widehat{q}_{1} ight)\) and \(E\left(\widehat{q}_{2} ight)\)...
-
Consider the following unbalanced one-way analysis of variance model \[y_{i t}=\mu_{i}+u_{i t} \quad i=1, \ldots, N \quad t=1,2, \ldots, T_{i}\] where for simplicity's sake no explanatory variables...
-
Consider the three-way error component model described in problem 3.15. The panel data can be unbalanced and the matrices of dummy variables are \(\Delta=\left[\Delta_{1}, \Delta_{2}, \Delta_{3}...
Study smarter with the SolutionInn App