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
- JAVA Determine the output for the following code public class Beta extends Baap { public int h = 44; public int getH( ) { System.out.println("Beta " + h); return h; } public static void main(String[ ] args) { Baap b = new Beta(); System.out.println(b.h + " " + b.getH( )); Beta bb = (Beta) b; System.out.println(bb.h + " " + bb.getH( )); } } public class Baap { public int h = 4; public int getH( ) { System.out.println("Baap " + h); return h; } }arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. public class MainClass{ public static void main(String[] args) { SomeClass myObject = new SomeClass(4, 5); int fred = SomeClass.SOME_VALUE; int barney = myObject.method1(); int wilma = SomeClass.method2(4); }} Which of the following is a static variable a method1 b method2 c SomeClass d SOME_VALUE e This cannot be determined by examining the above codearrow_forwardWhat is the out put of the following code ? explain your answer ? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } public class A { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }arrow_forward
- use Java. Given the following class. public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.arrow_forwardWrite java program that meets the following specifications: (use your own example and data values) Class A with Two private instance variables of type Double and String with default values. Two overloaded constructors - a default constructor with no argument, and a constructor which takes a double argument. Two public methods Class B (Main class) to demonstrate and execute code.arrow_forwardQuestion :- Add a statement to the classA to test whether myChar is accessible. public class ClassB { public int x = 1; int y = 2; private int z =3; } public class ClassA { public static void main(String[] args) { ClassB cb = new ClassB(); // System.out.print(cb.x); /* 1 */ // System.out.print(cb.y); /* 2 */ // System.out.print(cb.z); /* 3 */ } }arrow_forward
- The following is in Java: public class MyClass { private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; } } 1) What is the problem? 2) In a few sentences how can the issue be fixed?arrow_forwardUse the Java program in below, implement encapsulation on the property name, and use getters and setters to unhide the name: class Animal1{String name; public void eat(){System.out.println("I can eat");}} class Dog extends Animal1{public void display(){System.out.println("My name is " + name);}} public class Lab06_A{public static void main(String[] args){ Dog labrador = new Dog(); labrador.name = "Rohu";labrador.display(); labrador.eat();} }arrow_forwardWhat is the output of the following code? 1: class Arthropod2: public void printName(double input) { System.out.print("Arthropod"); }3: }4: public class Spider extends Arthropod {5: public void printName(int input) { System.out.print("Spider"); }6: public static void main(String[] args) {7: Spider spider = new Spider();8: spider.printName(4);9: spider.printName(9.0);10: }11: } A. SpiderArthropodB. ArthropodSpiderC. SpiderSpiderD. ArthropodArthropodE. The code will not compile because of line 5.F. The code will not compile because of line 9. Please explain how this code works each line.arrow_forward
- 4- Consider the following program:public class ClassA{public void dothat(ClassB c1, ClassC c2){//method content goes here}}public class ClassB extends ClassA{}public class ClassC extends ClassB{}public class Main{public static void main(String[]args){ClassA c1 = new ClassA();ClassB c2 = new ClassB();ClassC c3 = new ClassC();}}Which of the following is a correct call to dothat? Why?a. c1.dothat(c1,c1);b. c2.dothat(c2,c2);c. c3.dothat(c1,c1);d. c2.dothat(c3,c2);e. c3.dothat(c3,c3);arrow_forwardI have the following code in java, replit: //First class public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random random = new Random(); Game game = new Game(console, random); game.startGame(); console.close(); }} //Second class import java.util.Scanner; public class Player { private String name; private int totalGames; private int totalGuesses; private int bestGame; public Player() { this.name = null; this.totalGames = 0; this.totalGuesses = 0; this.bestGame = Integer.MAX_VALUE; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getTotalGames() { return totalGames; } public void setTotalGames(int totalGames) { this.totalGames = totalGames; } public int getTotalGuesses() { return totalGuesses; } public void setTotalGuesses(int totalGuesses) {…arrow_forward2- Consider the following program:public class Product{ private int price;public void setPrice(int theprice){price = thePrice;}}public class SpecialProduct extends Item{ private int discount;public void setDiscount(int theDiscount){discount = theDiscount;}}public class Main{public static void main(String[]args){SpecialProduct product = new SpecialProduct();}}Which of the following compiles without a problem? Why?a. product.discount = 20;b. product.setDiscount(20);c. product.setPrice(50);arrow_forward
- 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