myClassObject is an instance of MyClass. What is printed when myClassObject.doSomething(2); is run? public class MyClass { private int num; } public MyClass() { num= 5; 25 } public void doSomething (int num) { O 52 } an error will be thrown System.out.print(num); System.out.print(this.num); none of these is correct nothing because the MyClass class will not compile
Q: Consider public class MyClass { public MyClass(){/code/} // more code… } To instantiate MyClass, you…
A: Given Code: public class MyClass { public MyClass() { /code/ } // more code… } Answer: MyClass mc =…
Q: True or False: An anonymous inner class must implement an interface or extend another class.
A: It can extend exactly one class and implement exactly one interface. It can extend exactly one class…
Q: The picture is code tester public class WordVowels { // Step 2: Declare an instance variable to…
A: ================================================== Here is the Word.java class…
Q: In the file Calculator.java, write a class called Calculator that emulates basic functions of a…
A: Given code of LabProgram.java file: import java.util.Scanner; public class LabProgram {public static…
Q: Study the following class interface for the class Aeroplane: class AeroPlane { public: void…
A: The `AeroPlane` class is designed to model essential characteristics of an airplane, namely its…
Q: This main class implements two classes NFA player and NBA player. Generate a JUnit test case for…
A: Code in JUnit.
Q: Java Program This assignment requires one project with two classes. Class Employee Class…
A: Solution: I have solved the given problem according to the given instructions. Please look at the…
Q: The base class Pet has protected fields petName, and petAge. The derived class Cat extends the Pet…
A: The main() method of a program that makes instances of the Pet and Cat classes and prints their…
Q: public void makeNoise() { System.out.println("talk"); }//end method makeNoise }//end class Animal…
A: core concept:- Inheritance :- when a parent class property is reused in its derived class then this…
Q: Can you complete? public class Student { // TODO: Build Student class with private fields and…
A: Algorithm : Step 1 : define the class Student. Step 2 : declare private data members. default…
Q: Modify the FrultBasket class as follows: - Fruit baskets should have one attribute basket: an array…
A: public class Fruit { //attributes protected String name = null; protected String colour = null;…
Q: Define class Shape, 2DShape and 3DShape as per UML class diagram given. Define all mutator…
A: public class Shape{ //declaring instance variables private double length; private double…
Q: 5 Select one or more options from the list cat.getAge(); O cat.getName(); cat.getColor();…
A: Explanation: I have created a main class to for compiling this program, The methods that are in…
Q: It has just one Main class which tests abstract class Animal and its 3 subclasses: Dog, Cat, and…
A: Question given: A program code is given of driver class. Write all classes and their method that…
Q: Java Programming Please do not change anything in Student class or Course class class John_Smith…
A: Hey there,I am writing the required solution for the above mentioned question below.
Q: Consider the Speaker interface shown below: public interface Speaker { public void speak(); }…
A: GIVEN: Create a Java program with 2 classes Human and Dog, both will implement the Speaker…
Q: Which of the following best explains why the getAge method will NOT work as intended?
A: Inside class there is one constructor which set the value of age. and there is one getter which is…
Q: Show StudentsADT interface
A: package xyz;public class Course { private String courseName;private String sectionNumber;private…
Q: A Door Class A computer game usually has many different objects that can be seen and manipulated.…
A: Q: Code the given problem
Q: Override the Person class’s speak function inside the Student class. Make the function print “I’m a…
A: Given: Override the Person class’s speak function inside the Student class. Make the function print…
Q: Extend the ItemToPurchase class per the following specifications: Private fields string…
A: import java.util.*;import java.lang.*;import java.io.*; class Item{ private String itemName;…
Q: Input Your output Expected output Dobby 2 Kreacher 3 Scottish Fold Pet Information: Name: Dobby Age:…
A: public class Cat extends Pet { private String breed; public void setBreed(String userBreed) {…
Q: Code the StudentAccount class according to the class diagram Methods explanation: pay(double):…
A: Here I have created a class names StudentAccount In this class, I have created a function to add the…
Q: The class Thingy is defined as shown below. public class Thingy { private int stat; public…
A: Required: To run the code and determine the output. code and screenshot are in the next step with…
Q: create an array of Employee objects. create an ArrayList of Employee objects from that array. use…
A: To do: create an array of Employee objects. create an ArrayList of Employee objects from that…
Q: Below is the definition for a class called "Fruit": public class Fruit { } private String name;…
A: In this question an implementation of the Fruit class is given and a main method needs to be…
Q: This lab demonstrates when a super class requires arguments and the child does not, but we still…
A: Your java program is given below as you required with an output.
Step by step
Solved in 3 steps
- public class OfferedCourse extends Course { // TODO: Declare private fields // TODO: Define mutator methods - // setInstructorName(), setLocation(), setClassTime() // TODO: Define accessor methods - // getInstructorName(), getLocation(), getClassTime() } import java.util.Scanner; public class CourseInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Course myCourse = new Course(); OfferedCourse myOfferedCourse = new OfferedCourse(); String courseNumber, courseTitle; String oCourseNumber, oCourseTitle, instructorName, location, classTime; courseNumber = scnr.nextLine(); courseTitle = scnr.nextLine(); oCourseNumber = scnr.nextLine(); oCourseTitle = scnr.nextLine(); instructorName = scnr.nextLine(); location = scnr.nextLine(); classTime = scnr.nextLine(); myCourse.setCourseNumber(courseNumber); myCourse.setCourseTitle(courseTitle);…Consider public class MyClass { public MyClass(){/code/} // more code… } To instantiate MyClass, you would write? MyClass mc = new MyClass(); MyClass mc = MyClass; MyClass mc = MyClass(); MyClass mc = new MyClass; public static int foo(int a, String s) { s = “Yellow”; a=a+2; return a; } public static void bar() { int a=2; String s = “Blue”; a = foo(a,s); System.out.println(“a=”+a+” s=”+s); } public static void main(String args[]) { bar(); } What is printed on execution of these methods? a = 4 s = Blue a = 5 s = Yellow a = 3 s = Yellow a =2 5 s = Blue What is true about private fields of a class? They must be used with private methods. They are accessible from anywhere inside or outside of a class. They can never be used in a class. They can be accessed only by methods inside the class they are associated with.Write a constructor for the IceCreamCup class. The constructor takes the name, and a List of Flavor s (name it fList) as parameters. It initializes the instance variables with the parameters. Use shallow copy for initializing the list of Flavor s. (Throw an IllegalArgumentException if the name is null, or the Flavor list is null or empty.) Note that successful instantiation should increase nCups by 1.
- public class Father { public String name; public int age; // customer name Father(){ name=”Hassan”; age=50;} public void display(){ System.out.println(“Name:”+name); System.out.println(“Age:”+age); } } 1. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. 2. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). 3. Define a method display () in class Child, execute the display ( ) method in superclass using the keyword super. Method display ( ) in class Child should print the information of name, age and location 4. Create other class named Main for the main method and create 2 objects for the 2 classes (Father and Child). Then execute the display ( ) method for Father and Child. Example of the output as in Figure 4: Father's info: Name: Josh Age: 50 Child's info: Name: Christy Age: 20 Location:…For the following four classes, choose the correct relationship between each pair. public class Room ( private String m type; private double m area; // "Bedroom", "Dining room", etc. // in square feet public Room (String type, double area) m type type; m area = area; public class Person { private String m name; private int m age; public Person (String name, int age) m name = name; m age = age; public class LivingSSpace ( private String m address; private Room[] m rooms; private Person[] m occupants; private int m countRooms; private int m countoccupants; public LivingSpace (String address, int numRooms, int numoccupants) m address = address; new int [numRooms]; = new int [numOceupants]; m rooms %3D D occupants m countRooms = m countOccupants = 0; public void addRoom (String type, double area)Point out errors in the following codes and correct them publicclass CheckingAccount { // Create attributes account Num, Balance privateint accountNum; // Account Number privatedouble balance; // Account balance // Constructor public void CheckingAccount(int aNum, double balance) { // Call setters to initialize attribute values setAccountNumber (aNum); setBalance; } // Setters public void setAccountNumber(int aNum) { if (accountNum >= 100) { accountNum = aNum; } else {System.out.println("This account number is invalid (Account number must be at least 3 digits)!"); this.accountNum = 100; // assign a default value } } public void setBalance(double aBalance) { // make sure the value is positive if (aBalance > 0) { aBalance = balance; } else { System.out.println("This balance value is invalid (input must be positive)!"); aBalance = 0; // assign a default value } } // Getters publicvoid getAccountNumber() { return accountNum; } public void getBalance() { return balance; }…
- public class SharedCounter {int counter = 0;public static void main(String [] args) throws InterruptedException{IntCell intCell = new IntCell();//Create incrementer and decrementer objects and pass intCell to the constructor. //Call .start() on both, then .join() on both.//Finally, print the value of intcell: intCell.getVal();} } class IntCell{private int val = 0;synchronized void increment() {val++;}synchronized void decrement() {val--;}int getVal() {return this.val;}} class Incrementer extends Thread{//IntCell reference //Set via parameterized constructor //Override the run method with a for loop that runs 10000 times and calls intCell.increment();} class Decrementer extends Thread{//IntCell reference //Set via parameterized constructor //Override the run method with a for loop that runs 10000 times and calls intCell.decrement();}Java programming language I need the two classes ( the testing class and the class with the methods) to be combined into one class. This is the program: import java.util.Scanner; //The Temperature Class Begins Here public class Temperature { private double ftemp; //The constructor public Temperature(double ftemp) { this.ftemp = ftemp; } //Get farenheit Method public double getFtemp() { return ftemp; } //Set farenheit method public void setFtemp(double ftemp) { this.ftemp = ftemp; } // Get Celcius Method public double getCelcius(double ftemp){ //double celcius = (double) (5/9) * (ftemp - 32); double celcius = (ftemp-32)* (double)5/9; return celcius; } // Get Kelvin Method public double getKelving(double ftemp){ double Kelvin; Kelvin = (ftemp-32)*(double)5/9 + 273.15; return Kelvin; } } //The Temperature Class Ends Here //The Temperature Test Class with a main method begins Here class…solve:
- toString() and equals() Methods This lab will demonstrate how the toString() and equals() methods work when they are not overridden. Type up the code and submit the BOTH results. CODE public class ObjectToString( public static void main(String[] args) { ClassOne co new ClassOne(); ClassTwo ct = new ClassTwo(); } } public class Classone { System.out.println(co); System.out.println(ct); System.out.println(co.equals(ct)); public void printfle() { System.out.println("I am from ClassOne"); } public class ClassTwo ( public void printMe() { } System.out.println("I am from ClassTwo"); Run the program and notice the output.Consider the following class definition and answer the following questions: public class MyClass { I/fields private int x; private int y; llconstructors public MyClass() {x = 0; y = 0; } public MyClass(int a, int b) {x = a; y = b; I/methods public void ShowNumbers() { System.out.printin(x + y); public void setx(int a) { x = a; public void sety(int b) {y = b; public int getx() { return x; public int gety() { return y; public int getsum() { return (x + y); } public int getproduct() { return x*y; Give the outputs of the following segments written in the main method: a) MyClass Object1= new MyClass(12, 15); System.out.printin(Object1.getx() +* *+ Object1.gety(); b) MyClass Object2= new MyClass( ); Object2.setx(5); Object2.sety(8); Object2.ShowNumbers( ); System.out.printin(Object2.getsum() + +Object2.getproduct());class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x 0; %3D this.y = 0; } %3D } class Overload_methods { public static void main(String args[]) { overload obj int a = 2; double b - 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + } = new overload(); + obj.y); } #3Run the code