We have to calculate the area of a rectangle, a square and a circle. Create an abstract class "Shape" with three abstract methods namely "RectangleArea"; taking two parameters, "SquareArea" and "CircleArea" taking one parameter each. The parameters of "RectangleArea" are its length and breadth, that of "SquareArea" is its side and that of "CircleArea" is its radius. Now create another class "Area" containing all the three methods "RectangleArea", "SquareArea" and "CircleArea" for printing the area of rectangle, square and circle respectively. Create an object of class "Area" and call all the three methods. Pakistan Updates January 02, 2021 Java Programs 0 Comments Here are some additional points to consider before writing the code: In Java, we use the abstract keyword to define abstract classes and met...
Create an abstract class "Animals" with two abstract methods "cats" and "dogs". Now create a class "Cats" with a method "cats" which prints "Cats meow" and a class "Dogs" with a method "dogs" which prints "Dogs bark", both inheriting the class "Animals". Now create an object for each of the subclasses and call their respective methods. Pakistan Updates January 02, 2021 Java Programs 3 Comments Source Code.. abstract class Animals { public abstract void cats(); public abstract void dogs(); } class Cats extends Anim...
How can you create an abstract class in Java with a constructor and abstract and non-abstract methods? Can you provide an example of a subclass that inherits the abstract class and implements the abstract method? Pakistan Updates January 02, 2021 Java Programs 0 Comments Meta Description: Learn how to create an abstract class with a constructor and abstract and non-abstract methods in Java. See an ex...
We have to calculate the percentage of marks obtained in three subjects (each out of 100) by student A and in four subjects (each out of 100) by student B. Create an abstract class "Marks" with an abstract method "getPercentage". It is inherited by two other classes "A" and "B"; each having a method with the same name which returns the percentage of the students. The constructor of student A takes the marks in three subjects as its parameters and the marks in four subjects as its parameters for student B. Create an object for each of the two classes and print the percentage of marks for both the students. Pakistan Updates January 02, 2021 Java Programs 0 Comments Source Code.. //@author Java_Programs abstract class Marks { public abstract float getPercentage(); } class A extends...
Create an abstract class "Bank" with an abstract method "getBalance". $100, $150 and $200 are deposited in banks A, B and C respectively. "BankA", "BankB" and "BankC: are subclasses of class "Bank", each having a method named "getBalance". Call this method by creating an object of each of the three classes. Pakistan Updates January 02, 2021 Java Programs 0 Comments There are a few things to note about the code: We have used abstract keyword to define the Bank class and its abstract method getBal...
Create an abstract class "Parent" with a method ";message". It has two subclasses each having a method with the same name "message" that prints "This is first subclass" and "This is second subclass" respectively. Call the methods "message" by creating an object for each subclass. Override java classis.. Pakistan Updates January 02, 2021 Java Programs 0 Comments First, we create an abstract class called "Parent" with an abstract method called "message". The "abstract" ...
Make a class named "Rectangle" having two data members, length and breadth and a method area () for calculating the area. The following three constructors should be there in your class: a. No args/parameter less constructor: Length and breadth values should be assigned zero. b. Parameterized constructor (1 parameter): Length and breadth values should be same. c. Parameterized constructor (2 parameters): Length and breadth values should be assigned by 2 parameters respectively. Pakistan Updates December 28, 2020 Java Programs 0 Comments here's an implementation of the Rectangle class public class Rectangle { private double length; private double breadt...
Make a class named ‘Courses’. While creating an object of the class, if nothing is passed to it, then the message "I am not enrolled in any course yet" should be displayed. If some course name(s) is/are passed to it, then in place of "I am not enrolled in any course yet" the name(s) of the courses should be displayed. Pakistan Updates December 28, 2020 Java Programs 0 Comments Here's an implementation of the Courses class that meets the requirements mentioned in the prompt: Source Code.. public class Cour...
Write a java program that creates an "Employee" class having the following methods "getInfo ()" this method takes the salary, number of hours of work per day of employee as parameter. "addBonus ()" this method adds $15 to the salary of the employee if it is less than $600. "addWork ()" this method adds $10 to the salary of employee if the number of hours of work per day is more than 8 hours. Print the final salary of the employee. Pakistan Updates December 28, 2020 Java Programs 0 Comments First, we define the Employee class Source Code.. class Employee { double salary; double workHours; // Constructo...
Create a class named "Employee" having the following two instance methods. a. getInfo() b. printInfo() The getInfo() method takes the information about employee’s name, year of joining, salary and city as parameter. The printInfo() method prints all the information Pakistan Updates December 28, 2020 Java Programs 0 Comments Here's a program that creates an Employee class with the getInfo() and printInfo() methods, and uses these methods to print inform...
Create a class named "Average" having a method calculateAverage () that calculates the average of three numbers entered by user and print the average. Pakistan Updates December 28, 2020 Java Programs 0 Comments Here's the code for the Average class: Source Code.. import java.util.Scanner; class Average { public static void calculat...
Write a program to print the area of a rectangle by creating a class named Area; having two methods. First method named as "setValues ()" that takes length and breadth of rectangle as parameters and the second method named as "getArea ()" that returns the area of the rectangle. Length and breadth of rectangle should be entered through keyboard. Pakistan Updates December 28, 2020 Java Programs 0 Comments Here's the program to solve the problem as described: Source Code.. import java.util.Scanner; public class Area { double le...