public String toString(); //returning string type
{
return “\nName: “ + name + “\nAge: “ + age; //return only returns 1 datatype
}
// printf, println suppose to work with primitive datatype
promotion: conver to upper datatype.
ex. float → double, int → long, float, double
variable 가 선언 된 후 (int x) 그 블럭{} 안에서만 사용할 수 있다는 것. it is not transferring to other block.
method same name w/ different signature.(not parameter)
public static void xyz(int x, String y){
//body
}
array of specific datatype[ ]
for (int e : array)
system.out.printf(”\n%d”, e);
%s = string
%d = double
%f = float or double
%n = line breaking
groups related classes, so that they could be imported into programs and reused.
Modifier | Class | Package | Subclass | World(outside of package) |
---|---|---|---|---|
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
no modifier | Y | Y | N | N |
private | Y | N | N | N |
//field
protected int gear;
protected int speed;
public class Bicycle(int gear, int speed){} ← Super class
class MountainBike extends Bicycle { ← Sub class
public mountainBike(int gear, int speed, int seatHeight){
super(gear, speed);
this.seatHeight - seatHeight;}
}
Abstract class can have both ‘abstract class’ and ‘concrete class’