Question

In: Computer Science

How to write a Java program that has a base class with methods and attributes, subclasses...

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.

Solutions

Expert Solution

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....


Related Solutions

write program that develop a Java class Dictionary to support the following public methods of an...
write program that develop a Java class Dictionary to support the following public methods of an abstract data type: public class Dictionary { // insert a (key, value) pair into the Dictionary, key value must be unique, the value is associated with the key; only the last value inserted for a key will be kept public void insert(String key, String value); // return the value associated with the key value public String lookup(String key); // delete the (key, value) pair...
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
Write in Java the following: A.  A bank account class that has three protected attributes: account number...
Write in Java the following: A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance. B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a...
Please write a java program that has the following methods in it: (preferably in order)   a...
Please write a java program that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled, and the total tuition Design Notes: The...
This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class. It works as a base for subclasses. You should learn about Java Inheritance before attempting this challenge.
1. Java Abstract Class (2 pts) () • A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class. It works as a base for subclasses. You should learn about Java Inheritance before attempting this challenge.• Following is an example of abstract class:abstract class Book{String title;abstract void setTitle(String s);String getTitle(){return title;}}If you try to create an instance of this class like the following line you will get an error:Book...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
In C++ write a program with a base class thet has a pure virtual function SALARY,...
In C++ write a program with a base class thet has a pure virtual function SALARY, and two derived classes. In the first derived class salary is increased by 20%, in the second derived class salary is increased by 30%
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print all elements of a linked list in order. B. Method to print all elements of a linked list in reverse order. C. Method to print all elements of a linked list in order starting from specific position. D. Method to join two linked lists into the first list in the parameters. E. Method to clone a linked list. The copy list has to be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT