ch8 done
This commit is contained in:
parent
0c4905f3af
commit
0732b3242b
Binary file not shown.
Binary file not shown.
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue