Show the output of following
1 public class Test {
2 public static void main(String[] args) {
3 A a = new A(3);
4 }
5 }
6
7 class A extends B {
8 public A(int t) {
9 System.out.println(“A’s constructor is Invoked”);
10 }
11 }
12
13 class B {
14 public B() {
15 System.out.println(“B’s constructor is invoked”);
16 }
17 }
Is the no-arg constructor of Object invoked when new A (3) is invoked?
Trending nowThis is a popular solution!
Chapter 11 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java How To Program (Early Objects)
Starting Out With Visual Basic (7th Edition)
Concepts Of Programming Languages
- 1) The UsingMethod class consists of a main method and a method called xMethod. What will the code print? public class UsingMethod {public static void main(String[] args) {double z = xMethod(3.5, 5.5);System.out.println(z);}public static double xMethod(double x, double y) {return x + y;}} 2) Identify the errors in the following programs a) 3 errorspublic class Test {public static void main(String[] args) {System.out.println(method2(3.4));} public static int method1(int n) {if (n > 0) return 1;else if (n == 0) return 0;else if (n < 0) return -1;}} b) 2 errorspublic class Test {public static void main(String[] args) {nPrintln(5, "Welcome to Java!");}public static void nPrintln(String message, int n) {for (int i = 0; i < n; i++) {System.out.println(message);}return n;}}arrow_forwardQUESTION 9 Public Class Employee { public static int y; Private int age; Public Employee(0{ age=0;} public int get_age() { return age;} Public Class Test { public static void main(String[] args) { Employee q = new Employee(); q.y=2; Employee.y=10; System.out.println("y=" + q.y); a. What is the output of the following code? b. Insert a System.out.println() statement that prints out q's agearrow_forward5) Consider the following code. public class Test { public static void main(String[] args){ NClass nc = new NClass(); nc.t += 1; } } class NClass { public imt t; private NClass() {//Constructor www. } } a) The program has a compilation error because the NClass class has a private constructor which is not accessible within the Test class. b) The program does not compile because the parameter list of the main method is wrong. c) The program compiles, but has a run time error because t has no initial value. d) The program compiles and runs fine.arrow_forward
- public class sample{public static int x = 100;public static int y = 150; }public class newspaper :sample{new public static int x = 1000;static void Main(string[] args){console.writeline(sample.x + " " + sample.y + " " + x);}} 100 150 1000 1000 150 1000 100 150 1000 100 150 100arrow_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }arrow_forward1- public class Con{ public static void main(String[] args) int[] ar=(2,5,7,9}; int i=2; final int j=1; 6. for (int x:ar) 8- { 9 if(ar[i]arrow_forwardPut a box around your answers for the outputs. Determine the output for #1 - 5, 1. int i = 2; while (i 0; i = i - 1) System.out.print( "yes"); 5. int total : 4; int i = 2; while (i < 5) total = total * i; is i+ 1; System.out.printIn("The total is " + total); 6. Rewrite #5 above using a for loop instead of a while loop.arrow_forwardpublic class MysteryReturn2 {3 public static void main(String[] args)4 {5 int x = 1;6 int y = 2;7 int z = 3;89 z = mystery(x, z, y);10 System.out.println(x + " " + y + " " + z);11 }1213 public static int mystery(int c, a, int b);14 {15 c--;16 a = 2 * b + c;17 b = a - 1;18 System.out.println(b + " " + c);1920 return a;21 }22 } 1. Line 13 contains 2 errors. What are they? 2. Rewrite line 13 with the errors identifed in Question 1 corrected.arrow_forwardComputer Science Java Language: Provide the equivalent UML Diagram for this code. public class ClassTest { public static void main (String args[]) { TestB objB = new TestB(); TestB objC = new TestB(); Testers objA = new Testers(); objA.Display(); } }arrow_forward1. Find the statement that causes the compilation error. 2. Determine the output if that statement is removed. public classC extends A { public void test() { System.out.print("C"); class A { public void test() { System.out.print("A"); } |} class B extends A { public static void main(String[] args) { A b1 = new A(); A b2 = new C(); b1 = (A)b2; A b3 = (B)b2; b1.test(); b2. test(); public void test() { System.out.print("B");arrow_forwardclass operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } Give result for the code Java Try to do ASAP ?arrow_forward3. a Given the following code: public class Test { public static void main (String [] args) { Object circlel = new Circle (); Object circle2 = System.out.println(circlel.equals (circle2)); new Circle (); class Circle { double radius; class Circle { double radius; public boolean equals (Circle circle) { public boolean equals (Object o) { return this.radius = circle.radius; return this.radius = ( (Circle) o).radius; i. Show the output from running Test using the Circle class in (a). ii. Show the output from running Test using the Circle class in (b). If Object is replaced by Circle in the Test class, what would be the output to run Test using the Circle class in (a) ? iii.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education