subject

Answer the following questions as briefly (but completely) as possible: 1. what is the printout of running the class c (via the command "java c") in the code below (saved in c. java)? (and, is that what you expected? ) 1: class a { 2: public a () { 3: system. out. println( "a's no-arg constructor is invoked" ); 4: } 5: } 6: 7: class b extends a { 8: } 9: 10: public class c {11: public static void main ( string [] args ) {12: b b = new b(); 13: }14: }2. what problem do you expect to see if compiling the program below? what was the error(s), if any, actually produced? 1: class a { 2: public a ( int x ) { 3: } 4: } 5: 6: class b extends a { 7: public b () { 8: } 9: }10: 11: public class c {12: public static void main ( string [] args ) {13: b b = new b(); 14: }15: }3 .which of the follow statements are true? which are false? explain why. a. a subclass is a subset of a superclass. b. when invoking a constructor from a subcass, its superclass's no-arg constructor is always invoked. c. you can override a private method defined in a superclass. d. you can override a static method defined in a superclass. 4. what is the benefit of using the @override annotation? 5. a. show the output of the following program: 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: } b. is the no-arg constructor of object invoked when new a(3) is invoked? 6. indicate true or false for the follow statements: a. you can always successfully cast an instance of a subclass to a superclass. b. you can always successfully cast an instance of a superclass to a subclass. 7. what's wrong with the following code? 1: public class test { 2: public static void main ( string [] args ) { 3: object fruit = new fruit(); 4: object apple = (apple) fruit; 5: } 6: } 7: 8: class apple extends fruit { 9: } 10: 11: class fruit { 12: }8. when overriding the equals method, a common mistake is mistyping its signature in the subclass. for example, the equals method is incorrectly written as equals (circle circle) as shown in (a) below. it should be written as equals(object circle), as shown in (b) below. show the output of running class test using the circle class first from (a), and then from (b). explain the output.1: public class test {2: public static void main ( string [] args ) {3: object circle1 = new circle(); 4: object circle2 = new circle(); 5: system. out. println( circle1.equals( circle2 ) ); 6: }7: }a. 1: class circle { 2: double radius; 3: public boolean equals ( circle circle ) { 4: return this. radius == circle. radius; 5: } 6: }b. 1: class circle { 2: double radius; 3: public boolean equals ( object circle ) { 4: return this. radius == ((circle) circle).radius; 5: } 6: } next, try adding the "@override" annotation to the equals method in (a), and then try compiling. repeat with (b). what are the results, and are they as you expected? 9. how would you prevent a class from being extended? how would you prevent a method from being overridden? 10 . which of the following classes define legal abstract classes a.1: class a { 2: abstract void unfinished ( ) { 3: } 4: }b.1: public class abstract a { 2: abstract void unfinished ( ) { 3: } 4: }c. 1: class a { 2: abstract void unfinished ( ) ; 3: }d. 1: abstract class a { 2: protected void unfinished ( ) ; 3: }e. 1: abstract class a { 2: abstract void unfinished ( ) ; 3: }f. 1: class a { 2: abstract int unfinished ( ) ; 3: }11. suppose a is an interface. can you create an instance using "new a()"? 12. which of the following (if any) is a correct interface declaration? (assume i1 and i2 are correctly defined elsewhere.)a. 1: interface a { 2: void print () { 3: }; 4: }b. 1: abstract interface a extends i1, i2 { 2: abstract void print () { 3: }; 4: }c. 1: abstract interface a { 2: print () ; 3: }d. 1: interface a { 2: void print () ; 3: }

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 17:00
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Janice usually works on a particular workbook that contains all business related data. she decides to keep a backup of all the data in a separate workbook. she opens a new workbook to transfer the data. which option should she use to copy all the data from one workbook to another workbook?
Answers: 1
question
Computers and Technology, 24.06.2019 17:40
Write a program to analyze student’s scores. each student’s id and 4 original test scores are saved in the attached file “student_id_scores.txt”. assume there are exactly 15 students in the class.• the program first opens the file, reads student’s ids and scores from the file and saves them in two arrays: o create a one-dimensional string array “ids” to store the student’s ids.o create a (parallel) two-dimensional int array “scores” to store student’s original test scores. this array has 5 columns, the original 4 test scores should be saved in the first 4 columns, and the last column will be used to save the average score after the calculation in next step.• the program then retrieves test scores from the array “scores”, calculates average score and determines the final letter grade based on the rules in the table below for each student. assume average score is integer value.average score = (score1 + score2 + score3 + score4) / 4average score letter grade90 ~ 100 a80 ~ 89 b70 ~ 79 c60 ~ 70 d0 ~ 60 f• the average score should be saved back in the 5th column of “scores” array.• create a new parallel one-dimensional char array “grades” to save each student’s letter grade.• program also needs to find the number of a, number of b, number of c, number of d and number of f grade. as well as the highest, lowest and average score of the class.• finally, program will display all of the original scores and all results on the computer screen using the format shown as the sample output below.• the program must contain at least the following functions: (1) a function “getscores” to read and store data into “ids” and “scores” arrays.(2) a function “analyzescores” to calculate student’s average score, determine letter grade, get the number of a, b, c, d and f, find the highest, lowest and average score of the class.(3) a function “displayresults” to display all of the results
Answers: 3
question
Computers and Technology, 24.06.2019 20:20
3. write assignment statements that perform the following operations with the variables a, b, and c: a. adds 2 to a and assigns the result to b b. multiplies b times 4 and assigns the result to a c. divides a by 3.14 and assigns the result to b
Answers: 2
You know the right answer?
Answer the following questions as briefly (but completely) as possible: 1. what is the printout of r...
Questions
question
Mathematics, 10.11.2020 18:30
question
Law, 10.11.2020 18:30
question
Arts, 10.11.2020 18:30