Question: Note: Kindly provide the answers within 2 days. All the below questions related to the Java Programming language. 2. Take this code: public class Person

Note: Kindly provide the answers within 2 days. All the below questions related to the Java Programming language.

Note: Kindly provide the answers within 2 days. All the below questions

related to the Java Programming language. 2. Take this code: public class

Person { public String name; public int age; public Person() { this.name= "Person" ; this age = 0; } public Person (String name,

2. Take this code: public class Person { public String name; public int age; public Person() { this.name = "Person" ; this age = 0; } public Person (String name, int age) { this.name = name; this age = age; } } public class Student extends Person { public String department; public Student (String department) { This department = department; } public Student (String name, int age, String department) { super (name, age); this department department; } = } public class Faculty extends Person { } a. If you create a Student with Student s = new Student (Biology"), then you will find that, as expected, s. department Biology", but that the same time, Person" and s:age = 0. Why is this? b. If you create a Student with Student s = new Student(), the code will not compile, but if you create a faculty member with Faculty f = new Faculty ( ), it will compile. Why does the latter compile but the former does not? s.name = 3. Take a look at this method: public class question { public double characterkraction(String filename) { File file = new File(filename); FileReader fik = new FileReader(file); BufferedReader fileInput = new BufferedReader (fr); String intins = fileInput.readLine(); int countedchars = 0; while (inline_!= null) { if (inline contains ("the")) { sountedchars, += 3; inline = fileInput.readLine(); } double axeResultat = countedchars Lites length); return aveResultti } } a) This is not going to compile because of the IOExceptions raised by the FileReader constructor and Buffered Reader readLine methods. Modify the code so it will compile b) Add a try/catch block to catch any Runtime exceptions. You must add a separate try/catch block. What Runtime exception or exceptions could be raised that you will want to look out for? 4. Look at this object hierarchy as an example, which we used in a previous assignment: Fruit Apple Citrus Orange Lemon 1 Let's say instead we have the following objects: Vehicle Sedan PassengerTrain Coupe SUV Rail Pickup Truck Cargo Train Create a similar inheritance hierarchy for these objects. Explain your reasoning 5. Let's take a couple of classes, Shape and its subclass Circle. Not all code is shown: public abstract class Shape { public Shape (-String color, boolean iskilled) { } public abstract double getAreal.); } public class Circle { public Circle double radius, String color, boolean isFilled) { super color, is filled); this radius = radius; } -- public double getArea ) { return Math, RI* Math.Row this radius, 2); } } If we have the variable sh: Shape sh = new Circle 4, "red", true); What happens if you execute to method sh.getArea() ? Will you get an error since Shape:getArea() is abstract? Why or why not? If sh.getArea () gives a result, what will that result be? Why will it give that result? 6. Let's take two Classes, Aircraft and Bird. Both have various subclasses you would expect, Aircraft having HotAirBalloon, Glider, and Airplane, among others. Bird has subclasses Finch, Duck, Bluejay, and many others. Both Aircraft and Bird implement the Fly interface, which looks like this: public interface Fly { void goForward(); void goUp!); void goDown); void turnLeft); void turnRight.1); } a. Why would we design various subclasses of aircraft and birds while creating an interface like Fly and having the classes implement it? b. What's another class you could define that would implement Fly but wouldn't be a subclass of Bird or Aircraft? Explain why. subclass of Bird or Aircraft? Explain why. 7. Take the class Circle, where part of the code looks like this: public class Circle { public final static String NAME = "Circle"; } Let's say we have 1000 instances of circle in an array list: = ArrayList arrayList new ArrayList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!