Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class TwoDShaper_4{
private String title;

public TwoDShaper_4(double w, double h) {
// TODO Auto-generated constructor stub
width = w;
height = h;
}

public TwoDShaper_4() {
Expand Down Expand Up @@ -52,7 +53,7 @@ String showTitle() {
}


class Triangular_4 extends TwoDShaper_3{
class Triangular_4 extends TwoDShaper_4{

private String style;

Expand Down Expand Up @@ -103,7 +104,11 @@ public static void main(String[] args) {

System.out.println("Info for t0: ");
t0.showStyle();
t0.setHeight(9);
t0.setWidth(3);
t0.showDim();
t0.showTitle();
t0.showTheTitle();
System.out.println("Area is " + t0.area());

System.out.println();
Expand Down
144 changes: 144 additions & 0 deletions 144 Chapter7/theoretical/Using_super_to_call_superclass_constructor_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package theoretical;

class TwoDShaper_5{

private double width;
private double height;
String title;

public TwoDShaper_5(double w, double h) {
width = w;
height = h;
}

public TwoDShaper_5() {
// TODO Auto-generated constructor stub
}

TwoDShaper_5(double width, double height, String title){

this.width = width;
this.height = height;
this.title = title;

}


double getWidth() {
return width;
}

double getHeight() {
return height;
}

void setWidth(double w) {
width = w;
}

void setHeight(double h) {
height = h;
}

void showDim() {

System.out.println("Width and height are " + width + " and " + height);
}

String showTitle() {
return title;
}

void showTitle_2() {
System.out.println("Triangle is also " + title);
}

}


class Triangular_5 extends TwoDShaper_5{

private String style;

public Triangular_5() {
// TODO Auto-generated constructor stub
}

public Triangular_5(String s, double w, double h) {
super(w, h);

style = s;
}

Triangular_5(String style, String title, double width, double height){

super(width, height, title);

this.style = style;

}

double area() {
return getWidth() * getHeight() / 2;
}

void showStyle() {
System.out.println("Triangle is " + style);
}

String showTheTitle() {

return showTitle();

}

void showTheTitle_2() {
System.out.println("Triangle is also " + super.title);
}

}


public class Using_super_to_call_superclass_constructor_5 {

public static void main(String[] args) {
Triangular_5 t0 = new Triangular_5();
Triangular_5 t1 = new Triangular_5("filled", 4.0, 4.0);
Triangular_5 t2 = new Triangular_5("outlined", 8.0, 12.0);
Triangular_5 t3 = new Triangular_5("Slovenly", "Classy", 8.0, 9.0);

System.out.println("Info for t0: ");
t0.showStyle();
t0.setHeight(9);
t0.setWidth(3);
t0.showDim();
t0.showTitle();
t0.showTheTitle();
System.out.println("Area is " + t0.area());

System.out.println();

System.out.println("Info for t1: ");
t1.showStyle();
t1.showDim();
System.out.println("Area is " + t1.area());

System.out.println();

System.out.println("Info for t2: ");
t2.showStyle();
t2.showDim();
System.out.println("Area is " + t2.area());

System.out.println();

System.out.println("Info for t3: ");
t3.showStyle();
t3.showDim();
t3.showTitle_2();
t3.showTheTitle_2();
System.out.println("Area is " + t3.area());

}

}
151 changes: 151 additions & 0 deletions 151 Chapter7/theoretical/Using_super_to_call_superclass_constructor_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package theoretical;


class TwoDShaper_6{

private double width;
private double height;
String title;

public TwoDShaper_6(double w, double h) {
width = w;
height = h;
}

public TwoDShaper_6() {
// TODO Auto-generated constructor stub
}

TwoDShaper_6(double width, double height, String title){

this.width = width;
this.height = height;
this.title = title;

}


double getWidth() {
return width;
}

double getHeight() {
return height;
}

void setWidth(double w) {
width = w;
}

void setHeight(double h) {
height = h;
}

void showDim() {

System.out.println("Width and height are " + width + " and " + height);
}

String showTitle() {
return title;
}

void showTitle_2() {
System.out.println("Triangle is also " + title);
}

}


class Triangular_6 extends TwoDShaper_6{

private String style;

public Triangular_6() {
// TODO Auto-generated constructor stub
}

public Triangular_6(String s, double w, double h) {
super(w, h);

style = s;
}

Triangular_6(String style, String title, double width, double height){

super(width, height, title);

this.style = style;

}

double area() {
return getWidth() * getHeight() / 2;
}

void showStyle() {
System.out.println("Triangle is " + style);
}

String showTheTitle() {

return showTitle();

}

void showTheTitle_2() {
System.out.println("Triangle is also " + super.title); // super is redundant here.
}

void showTheTitle_3() {
System.out.println("Triangle is also " + title);
}

}


public class Using_super_to_call_superclass_constructor_6 {

public static void main(String[] args) {

Triangular_6 t0 = new Triangular_6();
Triangular_6 t1 = new Triangular_6("filled", 4.0, 4.0);
Triangular_6 t2 = new Triangular_6("outlined", 8.0, 12.0);
Triangular_6 t3 = new Triangular_6("Slovenly", "Classy", 8.0, 9.0);

System.out.println("Info for t0: ");
t0.showStyle();
t0.setHeight(9);
t0.setWidth(3);
t0.showDim();
t0.showTitle();
t0.showTheTitle();
System.out.println("Area is " + t0.area());

System.out.println();

System.out.println("Info for t1: ");
t1.showStyle();
t1.showDim();
System.out.println("Area is " + t1.area());

System.out.println();

System.out.println("Info for t2: ");
t2.showStyle();
t2.showDim();
System.out.println("Area is " + t2.area());

System.out.println();

System.out.println("Info for t3: ");
t3.showStyle();
t3.showDim();
t3.showTitle_2();
t3.showTheTitle_2();
t3.showTheTitle_3();
System.out.println("Area is " + t3.area());

}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.