java practice set 10,chapter 10

 package com.company;


class circle{
public int radius;
circle(){
System.out.println("not param of circle");
}
circle(int r){
System.out.println("circle parameterized constructor");
this.radius =r;
}

public double area(){
return Math.PI*this.radius*this.radius ;
}
}


class cylinder extends circle{
public int height;
cylinder(int r,int h){
super(r);
System.out.println("cylinder parameterized constructor");
this.height=h;
}

public double volume(){
return Math.PI*this.radius*this.radius * this.height;
}
}



class Rectanglee{
public int length, breadth;
Rectanglee(int a, int b){
this.length=a;
this.breadth=b;
}
}



class Cuboid extends Rectanglee{
public int side;
Cuboid(int s, int a, int b){
super(a,b);
this.side=s;
}

}


class Rectangle1{
public int length, breadth;
Rectangle1(int p, int d){
this.length=p;
this.breadth=d;

}

public void setBreadth(int breadth) {
this.breadth = breadth;
}

public void setLength(int length) {
this.length = length;
}

public int getLength() {
return length;
}

public int getBreadth() {
return breadth;
}

public int area(){
return this.length*this.breadth;
}


}

class cuboid extends Rectangle1{
public int side;
cuboid(int s, int p, int d){
super(p,d);
this.side=s;
}
public void setSide(int side){
this.side=side;
}

public int getSide() {
return side;
}

public int volume(){
return this.side*this.side*this.side;
}

}

public class cwh_chapter10_practice_set {
public static void main(String[] args) {

//problem1-----create a class circle use inheritance to create another class cylinder from it
//problem3-----create methods for area and volume problem1
circle objc=new circle(12);
cylinder obj =new cylinder(12,4);



//problem2-----create class rectangle use inheritance to create another cuboid try to keep as close of real world scenarios
//problem4---method for area and volume in problem 2also create getter and setter
Rectanglee objr=new Rectanglee(4,5);
Cuboid objl =new Cuboid(5,2,7);

}
}


















/*
answer for question 2:
class Rectangle1{
public int length, breadth;
Rectangle1(int a, int b){
this.length=a;
this.breadth=b;
}
}
class cuboid extends Rectangle1{
public int side;
cuboid(int s, int a, int b){
super(a,b);
this.side=s;
}

}


answer for question 4:
class Rectangle1{
public int length, breadth;
Rectangle1(int p, int d){
this.length=p;
this.breadth=d;

}

public void setBreadth(int breadth) {
this.breadth = breadth;
}

public void setLength(int length) {
this.length = length;
}

public int getLength() {
return length;
}

public int getBreadth() {
return breadth;
}

public int area(){
return this.length*this.breadth;
}


}

class cuboid extends Rectangle1{
public int side;
cuboid(int s, int p, int d){
super(p,d);
this.side=s;
}
public void setSide(int side){
this.side=side;
}

public int getSide() {
return side;
}

public int volume(){
return this.side*this.side*this.side;
}

}




*/

Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

java practice set 8

new stored procidure with interval and frequery code