Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Does each of the following programs compile and run? If no, explain the reason; otherwise, give the output. 1. class P1 { } }

 Does each of the following programs compile and run? If no, explain the reason; otherwise, give the output. 

  • student submitted image, transcription available below

    student submitted image, transcription available below

    student submitted image, transcription available below

    student submitted image, transcription available below


     
     
     
     
     


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 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");

Step by Step Solution

3.32 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

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... 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

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Programming questions