final lab Flashcards
the first step of every class you make:
identify the attributes (ex: private String name;)
the Scanner is used in the _____ class
main public class
how to make a getter? [what are the two steps] (ex: for private string attribute name for class trainee)
public String getName(){ //(step 1: make a PUBLIC method)
return name; //(step 2: use RETURN to return the wanted private value.)
}
what does a getter method do?
a getter method returns its value.
what does a setter method do?
sets or updates its value.
how do we declare/call out a private value?
using a getter
where do we create the getter and setter method?
in the same class the attribute is identified
the (setter/getter) method is always void.
setter
how to make a setter?
public class Vehicle {
private String color;
public void setColor(String c) {
this.color = c;
}
}
steps of making a parameterized constuctor:
1 - intialization for each value/attribute in the constructor (using <this> method or etc)</this>
when to use <this> method?</this>
when intializing a value that has the same name as an attribute in the class
when to use <this> method?</this>
when intializing a value that has the same name as an attribute in the class
write the code for f2 using method display()
f2.display();
(bs it’s that easy)
t/f: there is no variable type for a parameterized constructor.
true (ex: public Author(String n, String em, String gen){})
write a statement to intialize String gender as char gen.
Gender = gen.charAt(0);