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

Infanta Mano | Sciencx (2025-07-09T23:45:32+00:00) Single Inheritence. Retrieved from 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.