Skip to content

Instantly share code, notes, and snippets.

@hasinur1997
Last active May 24, 2018 14:50
Show Gist options
  • Save hasinur1997/d42513d7b328803a5663ebee6fe51ac4 to your computer and use it in GitHub Desktop.
Save hasinur1997/d42513d7b328803a5663ebee6fe51ac4 to your computer and use it in GitHub Desktop.

Question No 2(b)

Find the output of following program

public class Test {
    public static void main(String args[]){
        double d = 100.04;
        long l = (long)d;
        int i = (int)l;
        
        System.out.println("Double Value = " + d);
        System.out.println("Long Value = " + l);
        System.out.println("Integer Value = " + i);
    }
}

Output

Double Value = 100.04
Long Value = 100
Integer Value = 100

Comment ( I think this program of your question is Wrong )

Find the output of following program

class Demo {
    public int myMethod(int num1, int num2){
        System.out.println("First myMethod of class demoo");
        return num1 + num2;
    }
    
     public int mySecondMethod(int var1, int var2){
        System.out.println("Second myMethod of class demoo");
        return var1 - var2;
    }
}

public class Sample4 {
    public static void main(String args[]){
        Demo obj1 = new Demo();
        obj1.myMethod(10, 10);
        obj1.mySecondMethod(20, 12);
    }
}

Output

First myMethod of class demoo
Second myMethod of class demoo

Find the output of following program

class Teacher {
   String designation = "Teacher";
   String collegeName = "Beginnersbook";
   void does(){
       System.out.println("Teaching");
   }
}

public class PhysicsTeacher extends Teacher {
    String mainSubject = "Physics";
    
    public static void main(String args[]) {
      PhysicsTeacher  obj = new PhysicsTeacher();
        
        System.out.println(obj.collegeName);
        System.out.println(obj.designation);
        System.out.println(obj.mainSubject);
        obj.does();
    }
}

Output

Beginnersbook
Teacher
Physics
Teaching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment