Single Inheritence

//parent class
package Sangam;

public class Groceries {
public int groceries_money = 100;
String color = “red”;
static String grocery_name =”sangam”;

public static void main(String[] args) {
}
void madurai_rice(){
Syst…


This content originally appeared on DEV Community and was authored by Infanta Mano

//parent class
package Sangam;

public class Groceries {
public int groceries_money = 100;
String color = "red";
static String grocery_name ="sangam";

public static void main(String[] args) {
}       
    void madurai_rice(){
        System.out.println("madurai_rice");

    }
    }

//child class
package Sangam;

public class Vegetables extends Groceries{
public int vegetable_money = 50;

public static void main(String[] args) {

    //child object
    Vegetables vegetable = new Vegetables();
    System.out.println(vegetable.groceries_money);
    System.out.println(vegetable.color);
    System.out.println(vegetable.grocery_name);

    vegetable.madurai_rice();

}
}


This content originally appeared on DEV Community and was authored by Infanta Mano


Print Share Comment Cite Upload Translate Updates
APA

Infanta Mano | Sciencx (2025-07-09T23:45:32+00:00) Single Inheritence. Retrieved from https://www.scien.cx/2025/07/09/single-inheritence/

MLA
" » Single Inheritence." Infanta Mano | Sciencx - Wednesday July 9, 2025, https://www.scien.cx/2025/07/09/single-inheritence/
HARVARD
Infanta Mano | Sciencx Wednesday July 9, 2025 » Single Inheritence., viewed ,<https://www.scien.cx/2025/07/09/single-inheritence/>
VANCOUVER
Infanta Mano | Sciencx - » Single Inheritence. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/09/single-inheritence/
CHICAGO
" » Single Inheritence." Infanta Mano | Sciencx - Accessed . https://www.scien.cx/2025/07/09/single-inheritence/
IEEE
" » Single Inheritence." Infanta Mano | Sciencx [Online]. Available: https://www.scien.cx/2025/07/09/single-inheritence/. [Accessed: ]
rf:citation
» Single Inheritence | Infanta Mano | Sciencx | https://www.scien.cx/2025/07/09/single-inheritence/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.