6 WEEKS TRAINING

We provide 6 weeks industrial training in Java and Android to B.Tech, B.E. engineering graduates.

6 MONTHS TRAINING

We provide 6 Months live project based industrial training in Java and Android to B.Tech, B.E., MCA, BCA students.

CORPORATE TRAINING

We provide customized and cost effective corporate training in Java, Spring, Hibernate, Web Services, Android, and Angular JS.

Assignment 7: Use of Inheritance in Java

  • 10 questions Complexity: Medium

class Body
{
private String name; // data member to store the name of a body.
private double mass; // data member to store the mass of a body.
public Body(String n, double m) //constructor to initialize Body objects
{
//initialize the data members of the current object using the parameters.
}
public void display() //method to display the details of a body.
{
//Details of a body are displayed in the following format.
//Name: Body Name
//Mass: ... Kg
}
public double getMass() //method to return the mass of a body.
{
//Mass of the current body is returned.
}
}

class MovingBody extends Body
{
private double velocity; // data member to store the velocity of a moving body.
public MovingBody(String n, double m, double v) //constructor to initialize MovingBody objects
{
//initialize the data members of the current object using the parameters.
//Note: super class constructor should be used to initialze inherited data members.
}
public double momentum()//method to calculate the momentum of a moving body.
{
//calculate and return the momentum of the current moving body.
// momentum of a moving body is equal to the product of its mass and velocity.
}
public void display() //method to display the details of a moving body.
{
//Details of a moving body are displayed in the following format.
//Name: Body Name
//Mass: ... Kg
//Velocity: ... m/s
//Momentum: ... Kg m/s
//Note: super class display() method should be used to display the name and mass of the body.
}
}

Let the objects be initialized by ("Iron Ball", 2.5, 20) and ("Rolling Stone", 8, 5) values respectively.

java BodyTest ↵

First Body Details:
Name: Iron Ball
Mass: 2.5 Kg
Velocity: 20 m/s
Momentum: 50 Kg m/s

Second Body Details:
Name: Rolling Stone
Mass: 8 Kg
Velocity: 5 m/s
Momentum: 40 Kg m/s

Iron Ball will have more impact on the wall because its momentum is > the momentum of the Rolling Stone.

abstract class Number
{
abstract public void display();  // Method to display the value of a number.
abstract public Number add(Number n); // method to add two numbers.
public static void displaySum(Number n1, Number n2)
{
//Values of the given number and their sum are displayed as follows.
//First No. is: .......
//Second No. is: .......
//Their sum is: .......
}
}

class Rational extends Number
{
// data member to store the values of a rational number.
public Rational(int n, int d)
{
//initialize the current Rational object using the given parameters.
}
public void display()
{
//display the value of a Rational object in p/q format.
}
public Number add(Number n)
{
//Add the current and parameter Rational objects and return the result as a Rational object.
}
}

class Complex extends Number
{
// data member to store the values of a complex number.
public Complex(int r, int i)
{
//initialize the current Complex object using the given parameters.
}
public void display()
{
//display the value of a Complex object in a+bi format.
}
public Number add(Number n)
{
//Add the current and parameter Complex objects and return the result as a Complex object.
}
}

Let the Rational objects be initialized by (3, 5) & (1, 4)
and the Complex objects be initialized by (5, 4) & (3, 2).

java NumberTest ↵

Rational numbers and their sum:
First No.: 3/5
Second No.: 1/4
Their Sum: 17/20

Complex numbers and their sum:
First No.: 5+4i
Second No.: 3+2i
Their Sum: 8+6i

abstract class Cargo
{
private String to, from;
private double weight;
public Cargo(String to, String from, int weight)
{
//initializer statements
}
final public void display()
{
//Details of a Cargo are displayed in the following format
//Source: ..........
//Destination: ..........
//Weight: ..........
//Cargo Type: .............. //Name of the sub classes is the cargo type.
//Freight Charge: ......... //Calculated using the freight rate defined by the sub classes.
}
abstract public double getFreightRate();
}

class Normal extends Cargo
{
public Normal(String to, String from, int weight)
{
//initializer statements
}
public double getFreightRate()
{
//freight rate per kg of the cargo weight is returned.
}
}

class Express extends Cargo
{
public Express(String to, String from, int weight)
{
//initializer statements
}
public double getFreightRate()
{
//freight rate per kg of the cargo weight is returned.
}
}

Let the Normal cargo object be initialized by ("Mumbai", "Delhi", 500)
and the Express cargo object be initialized by ("Chennai","Jaipur",350).
Let the freight rate of normal cargo be 20 Rs/kg and express cargo 25 Rs/kg.

java CargoTest ↵

First Cargo details:
Source: Mumbai
Destination: Delhi
Weight: 500 Kg
Cargo Type: Normal
Freight Charge: 10000 Rs.

First Cargo details:
Source: Chennai
Destination: Jaipur
Weight: 350 Kg
Cargo Type: Express
Freight Charge: 8750 Rs.

abstract class Person
{
private String name;
private int age;
public Person(String name, int age)
{
//initializer statements
}
public void display()
{
//Details of a Person are displayed in the following format
//Name: ..............
//Age: .........
//Role: ............ //Name of the subclasses represents the role of a person.
}
}

class Student extends Person
{
private String course;
private int fee;
public Student(String name, int age, String course, int fee)
{
//initializer statements
}
public void display()
{
//Details of a Student are displayed in the following format
//Name: ..............
//Age: .........
//Role: ............ //Name of the subclasses represents the role of a person.
//Course: ..............
//Fee: .........
// Note: name, age and role should be displayed with the help of super class method.
}
}

class Employee extends Person
{
private String title;
private int salary;
public Emp(String name, int age, String title, int salary)
{
//initializer statements
}
public void display()
{
//Details of an Employee are displayed in the following format
//Name: ..............
//Age: .........
//Role: ............ //Name of the subclasses represents the role of a person.
//Title: ..............
//Salary: .........
// Note: name, age and role should be displayed with the help of super class method.
}
}

Define a class named PersonTest which contains main() method. In the main() method, one Student and one Employee objects are created and their details are displayed.

For queries:  8130-311-892,  9212-468-649

ONE YEAR VALIDITY

Admission is valid for one year i.e students can revise the course any number of times if popular fee plan is opted.

INDUSTRIAL TRAINING CERTIFICATION

Industrial training and course certificates are provided after the successful completion of each course.

PLACEMENT ASSISTANCE

We provide 100% placement assistance to all the students on the basis of monthly assessment tests.