Corejava-Basics-Types of Variables in java Part-3

Java

Video is ready, Click Here to View ×


This Video Session explains Corejava – Basics – Types of Variables in java. Training Tutorial delivered by our Trainer Ratan.
For more details visit : http://bit.ly/2d8XIN9

DURGASOFT is INDIA’s No.1 Software Training Center

Trainer Name : Mr.Ratan
Course : Core Java
Topic : Types of Variables in java
Methods of Training : Inclass, Online, Video based training

Location : 2nd Floor, Canara Bank Building, S.R Nagar, Hyderabad-500032
Contact Phone :…

22 thoughts on “Corejava-Basics-Types of Variables in java Part-3

  1. Sir if we declare static variable and for calling those variable in print fun. you said that we need to call by using class name .
    But I call directly and it compile prog and execute also

  2. Assignment-2:

    class Quiz
    {

    int a=100;
    float b=200;
    static double c=300;
    static int d=400;

    void m1()
    {
    System.out.println(a);
    System.out.println(b);
    System.out.println(Quiz.c);
    System.out.println(Quiz.d);
    }
    static void m2()
    {
    Quiz q= new Quiz();

    System.out.println(q.a);
    System.out.println(q.b);

    System.out.println(Quiz.c);
    System.out.println(Quiz.d);
    }
    public static void main(String[] args)
    {
    Quiz s= new Quiz();
    s.m1();
    Quiz.m2();
    }

    }

  3. Assighnment-1:

    class Quiz
    {
    int a=100;
    int b=200;

    static void m1()
    {
    Quiz q=new Quiz();
    System.out.println(q.a);
    System.out.println(q.b);
    }
    static void m2()
    {
    Quiz q=new Quiz();
    System.out.println(q.a);
    System.out.println(q.b);
    }
    public static void main(String [] args)
    {

    Quiz.m1();
    Quiz.m2();

    }

    }

  4. I have one question. If the Static variable that we want to access reside on the same source file under same class, then it seems like we don't even need to use class-name.variable to call the variable. We can just directly call them be it static or instance area. But we need to use class name if we are using a different class inside or another source file. Then only you need to use class-name.static-variable.

  5. Hi Ratan sir,

    Nice explanation on Java variables. Please find the following assignments which you have asked for :

    Assignments
    ================
    class Assignment1
    {
    //Declaration & initialization of instance variables.
    int a=10;
    double b= 20.0;
    static void m1()
    {
    System.out.println(obj.a);
    System.out.println(obj.b);
    }
    static void m2()
    {
    System.out.println(obj.a);
    System.out.println(obj.b);
    }
    public static void main(String []args)
    {
    Assignment1 obj = new Assignment1();
    obj.m1();
    obj.m2();
    }
    }

    Output:
    10
    20.0
    10
    20.0

    class Assignment2
    {
    //Declare & initialize two instance variables
    int a=10;
    float b= 10.0

    //Declare & initialize two static variables
    static int c=20;
    static float d=20.5;

    //m1 method is used to access these variables
    void m1()
    {
    //Instance area
    System.out.println(a);
    System.out.println(b);
    System.out.println(Assignment2.c);
    System.out.println(d);
    }
    static void m2()
    {
    //Static area
    System.out.println(obj2.a);
    System.out.println(obj2.b);
    System.out.println(c);
    System.out.println(d);
    }
    public static void main(String []args)
    {
    Assignment2 obj2 = new Assignment2();
    obj2.m1();
    Assignment2.m2();
    }
    }

    Output: 10
    10.0
    20
    20.5
    10
    10.0
    20
    20.5

  6. Assignment 2–

    class Test{
    int a=100;
    int b=200;
    static int c=300;
    static int d=400;
    void m1(){
    System.out.println(a);
    System.out.println(b);
    System.out.println(Test.c);
    System.out.println(Test.d);
    }
    static void m2(){
    Test t=new Test();
    System.out.println(t.a);
    System.out.println(t.b);
    System.out.println(Test.c);
    System.out.println(Test.d);
    }
    public static void main(String[] args){
    Test t1=new Test();
    t1.m1();
    Test.m2();
    }

    }

  7. Assignment 1

    public class Assignment {
    int a = 100;
    int b = 300;
    static void m1()
    {
    Assignment s = new Assignment();
    System.out.println(s.a);
    System.out.println(s.b);
    }
    static void m2()
    {
    Assignment k = new Assignment();
    System.out.println(k.a);
    System.out.println(k.b);
    }
    public static void main(String[] args) {

    m1();
    m2();

    }

    Assignment 2 complete

    public class Assignment2 {
    int a = 10;
    int b = 5;
    static int c = 15;
    static int d = 20;

    void m1()
    {
    System.out.println(a);
    System.out.println(b);
    System.out.println(Assignment2.c);
    System.out.println(Assignment2.d);
    }
    static void m2()
    {
    Assignment2 p = new Assignment2();
    System.out.println(p.a);
    Assignment2 k = new Assignment2();
    System.out.println(k.b);
    System.out.println(Assignment2.c);
    System.out.println(Assignment2.d);
    }
    public static void main(String[] args) {
    Assignment2 j = new Assignment2();
    j.m1();
    m2();

    }

    }

  8. unbelievable man.. I also complete the second assignment in first chance 😮

    class InstanceStatic
    {
    int a = 200;
    int b = 400;
    static int c = 300;
    static int d = 100;

    void m1()
    {
    System.out.println(a);
    System.out.println(b);
    System.out.println(InstanceStatic.c);
    System.out.println(InstanceStatic.d);
    }

    static void m2(InstanceStatic obj)
    {
    System.out.println(obj.a);
    System.out.println(obj.b);
    System.out.println(InstanceStatic.c);
    System.out.println(InstanceStatic.d);
    }

    public static void main(String[] args)
    {
    InstanceStatic obj1 = new InstanceStatic();
    obj1.m1();
    InstanceStatic.m2(obj1);
    }
    }

  9. Ratan, I complete 1st assignment 🙂 –> feeling Happy 🙂 ThankYou

    class Test
    {
    int a = 1000;
    int b = 3000;
    static void m1(Test s)
    {

    System.out.println(s.a+"m1");
    System.out.println(s.b+"m1");
    }
    static void m2(Test s)
    {

    System.out.println(s.a+"m2");
    System.out.println(s.b+"m2");
    }
    public static void main(String[] args)
    {
    System.out.println("Hello World!");
    Test t = new Test();
    t.m1(t);
    t.m2(t);
    System.out.println(t.a + "main");
    System.out.println(t.b + "main");
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *