10. Inside the class Student, we see the following code for the constructor:
public Student(String name) {
name = name
}
Unfortunately, Java gives us an error when we compile this code. Rewrite this constructor in the best way to correct the problem?
// Constructor
public Student(String name) {
//this is used to access the instance members of own class
// This line should be ends with semicolon ;
this.name = name;
}
10. Inside the class Student, we see the following code for the constructor: public Student(String name)...
Create a public constructor (a method with the same name as the class) inside the class Fish. This constructor should take in no arguments. Inside the constructor, set typeOfFish to “Unknown” and friendliness to 3, which we are assuming is the generic friendliness of fish.
(20 pts) Inside a method main, we see code like: Airplane.foo3(34.6); From this, reconstruct the header of method foo3 (which belongs to class Airplane); make appropriate assumptions if necessary. Write the method header as your answer. (20 pts) Inside method main, we see code like: Airplane a = new Airplane(); int n = a.foo4(“Hello”); From this, reconstruct the header of method foo4 (which belongs to class Airplane) Write the method header as your answer. (40 pts) You coded...
Analyze the following code: public class Test { public int x; public Test(String t) { System.out.println("Test"); public static void main(String[] args) { Test test: System.out.println(test.x); The program has a compile error because Test class does not have a default constructor The program has a compile error because test is not initialized OO The program has a compile error because x has not been initialized The program has a runtime NullPointerException while executing test.x because test is a null reference and...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...
Implement the following class in Java: Class name: People Constructor Summary: public People (String name) Methods: public People(String name) public void setName(String name) public String getName() Class name: Truck Constructor Summary: public Truck (int licensePlate, int onBoard, People people) Initially, the truck does not contain any on board the vehicle. If the number of people on board the vehicle is a negative number, the value of onBoard should be stored as zero. Methods: public int getLicensePlate() Returns license plate of...
Here is the code for the Infant class: public class Infant{ private String name; private int age; // in months public Infant(String who, int months){ name = who; age = months; } public String getName(){ return name;} public int getAge(){ return age;} public void anotherMonth() {age = age + 1;} } The code box below includes a live Infant array variable, thoseKids. You cannot see its declaration or initialization. Your job is to find out which Infant in the array...
10. Observe the following simple program: public class Student : Person { private string name; private List<string> courses; public void AddCourse(string course) { courses.Add(course); public void PrintCourses() { foreach(string course in courses) { Console.WriteLine(course); a) What is the access modifier of the member field name? b) What is the access modifier of the member method AddCourse? c) What is the immediate base class of Student?
Analyze the following code in these 2 Java classes and choose the correct statement below: public class Test { public static void main(String[] args) { Time1 time = new Time1(); time.print(); } } public class Time1 { private String showTime; public Time1(String newTime) { showTime = newTime; } public void print() { System.out.printf("%s", showTime); } } a. The program will compile and run if you change: Time1 time = new Time1(); → Time1 time = new Time1("5:15"); b....
Implement the following class in Java. Class name: Cakes Constructor Summary: public Leaderboard() - Create a leaderboard with no entries, and current number of cakes eaten to 0. Methods: public List getContestants() - Return a list of all the contestant scores in the format (Name:Score). Return an empty list if no entries inside list. Please provide a test to show your implementation works, thank you.