This commit is contained in:
marguesto 2022-06-18 00:39:51 +02:00
parent 0c4905f3af
commit 0732b3242b
20 changed files with 202 additions and 0 deletions

BIN
ch8/A.class Normal file

Binary file not shown.

BIN
ch8/Abstract.class Normal file

Binary file not shown.

38
ch8/Abstract.java Normal file
View File

@ -0,0 +1,38 @@
//final abstract class lain{ // ERROR, can't be inherited
// void pain(){
// System.out.println("Big bang");
// }
// //final void pain(){ // you can't stop java from compiling errors
// // System.out.println("Big bang");
// //}
//}
abstract class lain{
void pain(){
System.out.println("Big bang");
}
//final void pain(){ // you can't stop java from compiling errors
// System.out.println("Big bang");
//}
}
class habeba extends lain{
void pain(){
System.out.println("habeba is the only queen and true warrior"); // gotta stop simping real hard
}
}
class Abstract {
static public void main(String[] args) {
lain lainObj = new habeba();
lainObj.pain();
habeba habObj = new habeba();
habObj.pain();
System.out.println("heeeeeeeey");
System.out.println(habObj.toString());
System.out.println(habObj.hashCode());
}
}

BIN
ch8/B.class Normal file

Binary file not shown.

BIN
ch8/ColorTriangle.class Normal file

Binary file not shown.

BIN
ch8/Exp.class Normal file

Binary file not shown.

BIN
ch8/Shapes.class Normal file

Binary file not shown.

57
ch8/Shapes.java Normal file
View File

@ -0,0 +1,57 @@
class twoD{
private double width;
private double height;
double getWidth () {return width; }
double getHeight () {return height; }
void setW(double w) { width = w ;}
void setH(double h) { height = h ;}
twoD(){
}
twoD(double w,double h){
width = w;
height = h;
}
void showD(){
System.out.println("w: " + width + ", h: " + height);
}
}
class Triangle extends twoD{
String style;
Triangle( String s, double w, double h){
super(w,h);
style = s;
}
double area(){
return getHeight() * getWidth();
}
void showStyle(){
System.out.println(style);
}
}
class ColorTriangle extends Triangle{
private String color;
ColorTriangle(String c, String s, double w, double h){
super(s,w,h);
color = c;
}
}
class Shapes{
twoD fsf = new twoD();
public static void main(String[] args){
System.out.println("hhhhh");
}
}

BIN
ch8/Sub1.class Normal file

Binary file not shown.

BIN
ch8/Sub2.class Normal file

Binary file not shown.

BIN
ch8/Sup.class Normal file

Binary file not shown.

BIN
ch8/Triangle.class Normal file

Binary file not shown.

BIN
ch8/X.class Normal file

Binary file not shown.

BIN
ch8/Y.class Normal file

Binary file not shown.

32
ch8/hab.java Normal file
View File

@ -0,0 +1,32 @@
class X{
int a;
X(int i) {a=i;}
}
class Y{
int a;
Y(int i ) {a=i;}
}
class Z extends X{
int b;
Z(int i, int j){
super(j);
b = i;
}
}
class hab {
public static void main(String args[]){
X x = new X(10);
X x2;
Y y = new Y(5);
Z z;
x2 = x;
X x3;
x3 = new Z(4,4);
// z = new X(3); // should result in an error too
// x2 = y; // should result in a compilations error
}
}

BIN
ch8/habeba.class Normal file

Binary file not shown.

BIN
ch8/lain.class Normal file

Binary file not shown.

BIN
ch8/overriding.class Normal file

Binary file not shown.

75
ch8/overriding.java Normal file
View File

@ -0,0 +1,75 @@
class A{
int i,j;
A(int a, int b){
i=a;
j=b;
}
void show(){
System.out.println( i + j);
}
}
class B extends A{
int k;
B(int a, int b, int c){
super(a, b);
k = c;
}
void show() {
System.out.println(k);
}
}
class Sup {
void who () {
System.out.println("who in sup");
}
}
class Sub1 extends Sup{
void who() {
System.out.println("sub1");
}
}
class Sub2 extends Sup{
void who() {
System.out.println("sub2");
}
}
class Exp {
void who(Sup i){
i.who();
}
void IfWho(Sup i){
}
}
class overriding{
public static void main(String[] args){
A a = new A(1,2);
a.show();
B b = new B(1,2,3);
b.show();
Sup SupRef;
Sup SupObj= new Sup();
Sub1 Sub1Obj = new Sub1();
Sub2 Sub2Obj = new Sub2();
SupRef = SupObj;
SupRef.who();
SupRef = Sub1Obj;
SupRef.who();
SupRef = Sub2Obj;
SupRef.who();
Exp ExpObj = new Exp();
ExpObj.who(SupObj);
}
}

BIN
ch8/twoD.class Normal file

Binary file not shown.