What will be the result of compiling and running the following program? Select the one correct answer.
Question:
What will be the result of compiling and running the following program?
Select the one correct answer.
(a) The program will fail to compile.
(b) The program will compile, but will throw a ClassCastException at runtime.
(c) The program will compile, and print 0 when run.
(d) The program will compile, and print 1 when run.
(e) The program will compile, and print 2 when run.
Transcribed Image Text:
public class Polymorphism ( public static void main (String[] args) { A refl= new C(); B ref2 = (B) refl; System.out.println (ref2.f()); } } class A class B extends A { int f() { class C extends B { int f() { { int f() { return 0; } } return 1; } } return 2; } }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 33% (3 reviews)
e The program will print 2 when Systemoutprintlnref2f is executed The o...View the full answer
Answered By
Ayush Mishra
I am a certified online tutor, with more than 3 years of experience in online tutoring. My tutoring subjects include: Physics, Mathematics and Mechanical engineering. I have also been awarded as best tutor for year 2019 in my previous organisation. Being a Mechanical Engineer, I love to tell the application of the concepts of science and mathematics in the real world. This help students to develop interest and makes learning fun and easy. This in turn, automatically improves their grades in the subject. I teach students to get prepared for college entry level exam. I also use to teach undergraduate students and guide them through their career aim.
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Programmers Guide To Java SE 8 Oracle Certified Associate OCA
ISBN: 9780132930215
1st Edition
Authors: Khalid Mughal, Rolf Rasmussen
Question Posted:
Students also viewed these Computer science questions
-
You are required to prepare/submit an individual report discussing the following: Choose a Multinational Enterprise (MNE) listed on an internationally recognized Stock Exchange (including for...
-
What would be the result of compiling and running the following program? Select the one correct answer. (a) The code will not compile, because the array type int[] is incorrect. (b) The program will...
-
What will be the result of compiling and running the following program? Select the one correct answer. (a) The program will fail to compile. (b) The program will compile, and print 0 when run. (c)...
-
0 3 S 25 cos(x) sin (x) dx -T3
-
Two small silver spheres, each with a mass of 10.0 g, are separated by 1.00 m. Calculate the fraction of the electrons in one sphere that must be transferred to the other in order to produce an...
-
Long-term memory is an archive of information about past experiences in our lives and knowledge we have learned, but it is important to consider the dynamic qualities as well, such as how LTM...
-
5. The reserve for encumbrancespast-year account typically represents amounts recorded by a governmental unit for: a Anticipated expenditures in the next year b Expenditures for which purchase orders...
-
In early 2003, Bristol-Myers Squibb announced that it would have to restate its financial statements as a result of stuffing as much as $3.35 billion worth of products into wholesalers warehouses...
-
On January 15, 2011, Kaleesi Inc sold $190,000 in receivables to JSnows Co with recourse. JSnows Co charges a 3% fee upfront for receivables factored with recourse. Kaleesi Inc receives 70% of the...
-
The Accounts Receivable Confirmation Statistics working paper shown on the next page was prepared by an audit assistant for the 2013 audit of Lewis County Water Company, Inc., a continuing audit...
-
Which statements about the following program are true? Select the three correct answers: (a) The code will fail to compile. (b) The code defines a Planet is-a Star relationship. (c) The code will...
-
What will be the result of compiling and running the following program? Select the one correct answer. (a) The program does not compile because of errors in one or more calls to the compute() method....
-
Elsas Makeup Manufacturers provided the following income statement for last year: Required: Calculate the times-interest-earned ratio. Sales Cost of goods sold Gross margin Operating expenses...
-
Given the following differential equation, dydx = sin ( x + y ) Find the following: ( a ) The substitution u = ( b ) The transformed differential equation dudx = ( c ) The implicit solution, given...
-
Consider the following type declarations TYPE Alinteger; A2 pointer to float; A3 pointer to integer; T1 structure (x: integer; } T2 structure (x: A1; next pointer to integer; } b float; } a :...
-
https://www.viddler.com/embed/82b62f65 Questions: How do companies decide where to locate their facilities? Why has just-in-time inventory control become a dominant production process used in the...
-
Adjusting Entries for Interest At December 31 of Year 1, Portland Corporation had two notes payable outstanding (notes 1 and 2). At December 31 of Year 2, Portland also had two notes payable...
-
We want to get an idea of the actual mass of 235U involved in powering a nuclear power plant. Assume that a single fission event releases 200 MeV of thermal energy. A 1,000 MWe electric power plant...
-
a) Find an equation of the hyperplane through the points (1, 0, 0, 0), (2,1, 0, 0), (0,1,1, 0), and (0, 4, 0,1). b) Find an equation of the hyperplane that contains the lines (t) = (t, t, t, 1) and...
-
Write a program to move a signed number from smaller register to bigger register. Hint: movzx ax, bl Topic: Data Related Operators and Directives in assembly language
-
Suppose you are given an array, A, containing n distinct integers that are listed in increasing order. Given a number k, describe a recursive algorithm to find two integers in A that sum to k, if...
-
Given an unsorted array, A, of integers and an integer k, describe a recursive algorithm for rearranging the elements in A so that all elements less than or equal to k come before any elements larger...
-
Write a short recursive Java method that rearranges an array of integer values so that all the even values appear before all the odd values.
-
you are analyzing the cost of debt for a firm. Do you know that the firms 14 year maturity, 7.8 Percent coupon bonds are selling at a price of $834. The Barnes pay interest semi annually. If these...
-
***Please answer the following using excel and showcasing the formulas/calculations used*** thank you so much Financial information on AAA Ltd. is shown below. AAA Ltd. Income Statement For the Year...
-
2. In an account Anh Paglinawan currently has $216,670.00. At a rate of 8.00% how long will it take for them to have $298,390.00 assuming semi-annually compounding? (Hint: compute the exact years, do...
Study smarter with the SolutionInn App