here my previous post
class Over{
void printHi(){
System.out.println("hi iam over");
}
void printHi2(){
System.out.println("hi iam testing2");
}
}
public class TestOver extends Over{
Over hh ;
public static void main(String [] islam){
Over r=new Over();
TestOver f=new TestOver();
r.printHi();
f.printHi();
}
void printHi(){
hh.printHi2();}
\\\ why this in not legeal its compile but runtime error , i used the hh refrence to invoke the method,why should i make a new Over hh=new Over(); thanks i got the answers that it must be initalized and i got it but in this example here
public class Horse extends Animal {
private Halter myHalter;
public void tie(LeadRope rope) {
myHalter.tie(rope); //why i didnt make Halter myHalter=new Halter,this work but the previous example didnt work iam pretty confused
}
}
public class Halter {
public void tie(LeadRope aRope) {
// Do the actual tie work here
}
}
class Over{
void printHi(){
System.out.println("hi iam over");
}
void printHi2(){
System.out.println("hi iam testing2");
}
}
public class TestOver extends Over{
Over hh ;
public static void main(String [] islam){
Over r=new Over();
TestOver f=new TestOver();
r.printHi();
f.printHi();
}
void printHi(){
hh.printHi2();}
\\\ why this in not legeal its compile but runtime error , i used the hh refrence to invoke the method,why should i make a new Over hh=new Over(); thanks i got the answers that it must be initalized and i got it but in this example here
public class Horse extends Animal {
private Halter myHalter;
public void tie(LeadRope rope) {
myHalter.tie(rope); //why i didnt make Halter myHalter=new Halter,this work but the previous example didnt work iam pretty confused
}
}
public class Halter {
public void tie(LeadRope aRope) {
// Do the actual tie work here
}
}