I am currently reading the following tutorial and have gotten up through here http://docs.oracle.com/javase/tutorial/java/concepts/interface.html
Maybe I should not be thinking about this question now because the tutorial hasn't brought it up, but I have a question of good practice. According to the tutorial up to this point, if I want to define an object and its methods, I can do so within either a class, or I can take parts of it that I expect it to share in common with other objects and put it in a super class. Or, from what I understand, I can do the former but delay defining my method until MAIN by using the interface keyword instead. I have two questions.
If I have a superclass->class structure, is it possible also to use a sort of "superinterface" instead to delay parts of the definition of methods until the MAIN method? (Please correct my terminology if you know what I mean, and know that I am not speaking correctly.)
Whatever is possible, when is it desirable to use each one from the perspective of efficiency and also of someone who would read my code?
I am a beginner. Thanks!
Edit: "Example" Code included (as written in the Netbeans IDE) for completion.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
/**
*
* @author Jeff
*/
class percolation{
int site1 = 1;
int site2 = 0;
int site3 = 1;
void changesite1(int newValue){
site1 = newValue;
}
void changesite2(int newValue){
site2 = newValue;
}
void changesite3(int newValue){
site3 = newValue;
}
void printStates(){
System.out.println("site1:" + site1 + " site2:" + site2 + " site3:" + site3);
}
}
class extendedpercolation extends percolation{
int site4 = 0;
void changesite4(int newValue){
site4 = newValue;
}
void printStates1(){
System.out.println("site1:" + site1 + " site2:" + site2 + " site3:" + site3 + " site4:" + site4);
}
}
class percolationdemo{
public static void main(String[] args) {
extendedpercolation perc1 = new extendedpercolation();
extendedpercolation perc2 = new extendedpercolation();
// Invoke methods on
// those objects
perc1.changesite1(0);
perc1.changesite2(0);
perc1.changesite3(0);
perc1.changesite4(0);
perc1.printStates1();
perc2.changesite1(1);
perc2.changesite2(0);
perc2.changesite3(1);
perc2.changesite4(1);
perc2.printStates1();
}
}
MAIN
do you mean something likemain ( string argv [] )
? If so, we need to focus your question somewhat.main
.main
is just the entry point for your program.