In: Computer Science
How to write a Java program that has a base class with methods and attributes, subclasses with methods and attributes. Please use any example you'd like.
CODE:
class Demo2{
   int a=10,b=40;
   void add(){
       System.out.println("Sum of a and b
values is "+(a+b)+ "from Demo2");
   }
   void mul(){
       System.out.println("Multiplication
of a and b values is "+(a*b)+ "from Demo2");
   }
}
class Demo extends Demo2{
   int a=12,b=20;
   void print()
   {
       System.out.println("Sum of a and b
values is"+(a+b));
   }
   void multi(){
       System.out.println("Multiplication
of a and b values is "+(a*b));
   }
   public static void main(String[] args) {
       Demo d=new Demo();
       d.print();
       d.multi();
       d.add();
       d.mul();
   }
}
OUTPUT:

If you have any doubts please COMMENT....
If you understand the answer please give THUMBS UP....