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;
}
On this page of the site you can watch the video online Java program to access variables with different access specifiers with a duration of hours minute second in good quality, which was uploaded by the user Basic Code 20 February 2020, share the link with friends and acquaintances, this video has already been watched 596 times on youtube and it was liked by 11 viewers. Enjoy your viewing!