0% found this document useful (0 votes)
37 views2 pages

Java Code Examples and Classes

The document contains Java code defining various classes, including a parent Job class and a child SoftwareDeveloper class that overrides a method to calculate updated salary based on experience. It also includes a Triangle class for calculating area and perimeter, as well as an abstract Parent class with two subclasses demonstrating method overriding. Additionally, it features an abstract class with a constructor and a normal method, along with a subclass that implements the abstract method.

Uploaded by

cosmic.sus.73
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Java Code Examples and Classes

The document contains Java code defining various classes, including a parent Job class and a child SoftwareDeveloper class that overrides a method to calculate updated salary based on experience. It also includes a Triangle class for calculating area and perimeter, as well as an abstract Parent class with two subclasses demonstrating method overriding. Additionally, it features an abstract class with a constructor and a normal method, along with a subclass that implements the abstract method.

Uploaded by

cosmic.sus.73
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Complete Java Codes - Final Version

// Job Class (Parent)


class Job {
double salary;
int yearsOfExperience;
String jobPosition;
String companyName;

public Job(double salary, int yearsOfExperience, String jobPosition, String companyName) {


[Link] = salary;
[Link] = yearsOfExperience;
[Link] = jobPosition;
[Link] = companyName;
}

public void getSalary() {


[Link]("Base Salary: $" + salary);
}

public void displaySummaryDetails() {


[Link]("Job Position: " + jobPosition);
[Link]("Company: " + companyName);
[Link]("Experience: " + yearsOfExperience + " years");
[Link]("Salary: $" + salary);
}
}

// SoftwareDeveloper (Child Class)


class SoftwareDeveloper extends Job {
public SoftwareDeveloper(double salary, int yearsOfExperience, String jobPosition, String companyName
super(salary, yearsOfExperience, jobPosition, companyName);
}

@Override
public void getSalary() {
double updatedSalary = (yearsOfExperience > 3) ? salary * 1.3 : salary * 1.05;
[Link]("Updated Salary: $" + updatedSalary);
}
}

// Triangle Class
class Triangle {
int a, b, c;

public Triangle() {
this.a = 3;
this.b = 4;
this.c = 5;
}

public void calculateAreaAndPerimeter() {


double s = (a + b + c) / 2.0;
double area = [Link](s * (s - a) * (s - b) * (s - c));
[Link]("Triangle Area: " + area);
[Link]("Triangle Perimeter: " + (a + b + c));
}
}

// Abstract Parent Class


abstract class Parent {
abstract void message();
}

class FirstSubclass extends Parent {


void message() {
[Link]("This is the first subclass.");
}
}

class SecondSubclass extends Parent {


void message() {
[Link]("This is the second subclass.");
}
}

// Abstract Class with Constructor


abstract class AbstractDemo {
public AbstractDemo() {
[Link]("This is the constructor of the abstract class.");
}

abstract void a_method();

void normalMethod() {
[Link]("This is the normal method of the abstract class.");
}
}

class SubClass extends AbstractDemo {


void a_method() {
[Link]("This is an abstract method.");
}
}

You might also like