Create a package called test package; Define a class called foundation inside the test package; Inside the class, you need to define 4 integer variables; Var1 as private; Var2 as default; Var3 as protected; Var4 as public; Import this class and packages in another class. Try to access all 4 variables of the foundation class and see what variables are accessible and what are not accessible
---------------------------------------------------------------------------------------------------------------------------
import test.Foundation;
public class Test {
public static void main(String[] args) {
Foundation foundation = new Foundation();
foundation.Var4=10;
System.out.println(foundation.Var4);
//Var1,2,3 not accessible as they aren't set to public.
}
}
-------------------------------------------
package test;
public class Foundation {
private int Var1;
int Var2;
protected int Var3;
public int Var4;
}
In questa pagina del sito puoi guardare il video online Java program to access variables with different access specifiers della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Basic Code 20 febbraio 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 596 volte e gli è piaciuto 11 spettatori. Buona visione!