Question

In: Computer Science

Class Pie:        self__init__(self,a,b,c)            self.a = a            self.b = b       &n

Class Pie:

       self__init__(self,a,b,c)

           self.a = a

           self.b = b

           self.c = c

           return

Class Food():

    def _init__(self):   #this __init__ is not important for the example

          return

    def getPie(): #no parameter

         return (Pie) #Here is where I want to return the contents of the __init__ inside the Pie class.

So, I want to return the class Pie (the contents of __init__) inside of the class Food method getPie, which is a,b,c. How do I do that? This is Python.

Solutions

Expert Solution

class Pie:
    def __init__(self,a,b,c):
        
        self.a=a
        self.b=b
        self.c=c
class Food(Pie):
    def __init__(self,a,b,c):
        # invoking the constructor of  
                # the parent class   
        Pie.__init__(self,a,b,c)
        
        
    def getPie(self):
        print(self.a)
        print(self.b)
        print(self.c)


obj=Food(1,2,3)
obj.getPie()

When a class inherits from another class it inherits the attributes and methods of another class.

Here also class Food inherits from Pie and it is able to access attribute and methods of Pie.

To access parents class methods it can be done by simply call the constructor of Pie class inside the constructor of Food class and then Food class is able to access the methods and attributes of Pie class.


Related Solutions

(a) The n × n matrices A, B, C, and X satisfy the equation AX(B +...
(a) The n × n matrices A, B, C, and X satisfy the equation AX(B + CX) ?1 = C Write an expression for the matrix X in terms of A, B, and C. You may assume invertibility of any matrix when necessary. (b) Suppose D is a 3 × 5 matrix, E is a 5 × c matrix, and F is a 4 × d matrix. Find the values of c and d for which the statement “det(DEF) =...
Stock A has PIE:15   stock B has PIE : 35 A) which stock is better B) what...
Stock A has PIE:15   stock B has PIE : 35 A) which stock is better B) what does this difference tell us about there stocks C) which stock would perform be tter in the bull market
Poof if a) A is nonsingular b) N(A) = {0} c) rank(A) = n
Poof if a) A is nonsingular b) N(A) = {0} c) rank(A) = n
Find a primitive root for: (a) n = 18, (b) n = 50 (c) n =...
Find a primitive root for: (a) n = 18, (b) n = 50 (c) n = 27, (d) n = 625.
Make the following: a. frequency distribution b. pareto chart c. probability distribution d. pie graph for...
Make the following: a. frequency distribution b. pareto chart c. probability distribution d. pie graph for the following set of numbers : Prophecy - 15 out of 50 Advice - 7 out of 50 Wisdom - 17 out of 50 Compliments - 4 out of 50 Misc. - 7 out of 50
Evaluate if the followings are Cauchy sequences or not. (a) an= (-1)n (b) an= (-1)n/n (c)...
Evaluate if the followings are Cauchy sequences or not. (a) an= (-1)n (b) an= (-1)n/n (c) an = n/(n+1) (d) an = (cos n)/n
Question 1 a) Determine whether the language {a n b m c n | n >...
Question 1 a) Determine whether the language {a n b m c n | n > 0} is regular or not using pumping Lemma. b) Prove that the language {(ai bn | i, n > 0, i = n or i = 2n} is not regular using the Pumping Lemma.
Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 3) A two arg float, int constructor, and a three arg int, float, float constructor to instantiate objects, initialize variables read from the keyboard, display the sum Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
Consider the class C of all intervals of the form (a, b), a, b ∈ R,...
Consider the class C of all intervals of the form (a, b), a, b ∈ R, a < b and ∅. Show that C is closed under finite intersections but not under complementations or unions. Hint: to show closure of finite intersections, it is enough to prove closure for intersections of 2 sets.
The following information pertains to the Big Returns Fund: Cost Class "A" Class "B" Class "C"...
The following information pertains to the Big Returns Fund: Cost Class "A" Class "B" Class "C" Front-end load 5.57 0.00 0.00 Back-end load 0.00 5.34 0.89 Declining 1% per year First year only Management fee 0.80 0.80 0.80 12b-1 fee 0.30 0.60 0.80 For each share class, calculate (1) how much you would pay in initial commissions, (2) how much you would pay in back-end commissions if you sold after two years, (3) how much in value is lost to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT