Answered step by step
Verified Expert Solution
Question
1 Approved Answer
suppose that the programs are correct write the output of every program : Section A -Read the programs, and write the output. You may assume
suppose that the programs are correct write the output of every program :
Section A -Read the programs, and write the output. You may assume the programs are otherwise correct. (40 marks in total with 4 marks each) 1) 2) public class Example4 { public static void main(String[] args) { int myIntArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int sum = 0; for (int i=my IntArray.length-1; i>0; i--) { if (i % 3 == 0) { sum += my IntArray[i]; } } System.out.println(sum); } } public class Example2 { public static void main(String[] args) { int outer = 0; int inner = 0; for (int i = 0; i -2; j -= 2) { inner++; } outer++; } System.out.println("inner " + inner + ", outer } } class Example5 { public static void main(String[] args) { try { + outer); 3) method(); System.out.print('0'); } catch (Exception e) { System.out.print('1'); } System.out.print('2'); } public static void createException() { System.out.print('3'); throw new ArrayIndexOutOfBoundsException(); } public static void method() { try { createException(); System.out.print('4'); } catch (ArrayIndexOutOfBoundsException e) { System.out.print('5'); } finally { System.out.print('6'); } System.out.print('7'); } } public class Example8 { public static void main(String[] args) { try { callMethod(); } catch (Exception e) { System.out.print("will "); } System.out.print("win "); } public static void createException() { throw new ArithmeticException(); } public static void callMethod() { try { createException(); System.out.print("not "); } catch (ArrayIndexOutOfBoundsException e) { System.out.print("you "); } finally { System.out.print("I"); } System.out.print("never"); 4) } } class Base { 5) int m; 6) public Base() { m = m + 1; } } public class Example14 extends Base { public Example14() { m = m + 1; } public static void main(String[] args) { Example14 tb = new Example14(); System.out.println(tb.m); } } public class Example12 { public static void main(String args[]) { Test s = new Test("Hello!", "I love JAVA."); System.out.println(s.toString(); } } class Test { String s1, s2; public Test(String stri, String str2) { $1 = stri; S2 = str2; } public String toString() { return $1 + 2; } } class Father { String name = "Father"; int age = 45; public int getAge() { return age; } public String getName() { return name; } public void setAge(int a) { age = a; } 7) 8) } class Child extends Father { String name = "Child"; int age = 18; public int getAge() { return age + 1; } } class Example11 { public static void main(String args[]) { Father person = new Child(); System.out.println(person.getAge()); person.setAge(30); System.out.println(person.getAge()); System.out.println(person.getName()); } } class ParentClass{ int x = 1; int sum(int a, int b, int c){ return a + b + c; } int sum(int a, int b){ return a + b; } } class Childclass extends ParentClass{ public ChildClass() { X = 10; } int sum(int a, int b){ return a + b + 1; } } public class Example10{ public static void main(String args[]){ ParentClass p=new ChildClass(); System.out.println(p.sum(5,5,5)); System.out.println(p.sum(5,5)); System.out.println(p.x); } } class Test { int a = 10; void me (Test obj) { 9)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started