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