Java Training in Chennai – Basics – Learning – Part – V

Java Training in Chennai – Basics – Learning – Part – V 

This blog explains about Java Training in Chennai – Basics – Learning – Part – V. Some of them are discussed below .

     We have already about some programming in the previous blogs , Java Training in Chennai – Basics – Learning – Part – I , II , III & IV 

_________________________________________________________________

What is the output of this program?

    class A {

        public int i;

        private int j;

    }   

    class B extends A {

        void display() {

            super.j = super.i + 1;

            System.out.println(super.i + ” ” + super.j);

        }

    }   

    class inheritance {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

 

What is the output of this program?

    class A {

        public int i;

        public int j;

        A() {

            i = 1;

            j = 2;

                }

    }   

    class B extends A {

        int a;

                B() {

            super();

        }

    }   

    class super_use {

        public static void main(String args[])

        {

            B obj = new B();

            System.out.println(obj.i + ” ” + obj.j)    

        }

   }

 

What is the output of this program?

    abstract class A {

        int i;

        abstract void display();

    }   

    class B extends A {

        int j;

        void display() {

            System.out.println(j);

        }

    }   

    class Abstract_demo {

        public static void main(String args[])

        {

            B obj = new B();

            obj.j=2;

            obj.display();   

        }

   }

What is the output of this program?

    class A {

        int i;

        void display() {

            System.out.println(i);

        }

    }   

    class B extends A {

        int j;

        void display() {

            System.out.println(j);

        }

    }   

    class method_overriding {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

What is the output of this program?

    class A {

        public int i;

        protected int j;

    }   

    class B extends A {

        int j;

        void display() {

            super.j = 3;

            System.out.println(i + ” ” + j);

        }

    }   

    class Output {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

 

What will be the output of the following program?

public abstract class AbstractTest

{

    public int getNum()

    {

        return 45;

    }

    public abstract class Bar

    {

        public int getNum()

        {

            return 38;

        }

    }

    public static void main (String [] args)

    {

        AbstractTest t = new AbstractTest()

        {

            public int getNum()

            {

                return 22;

            }

        };

        AbstractTest.Bar f = t.new Bar()

        {

            public int getNum()

            {

                return 57;

            }

        };

        System.out.println(f.getNum() + ” ” + t.getNum());

    }

}

What will be the output of the following program?

public class Test {

    public static void main(String[] args) {

        new Z().method1();

        new Z().method2();

    }

}

abstract class X {

    abstract void method1();

    abstract void method2();

}

abstract class Y extends X {

    void method1() {

        System.out.println(“Method1 implemented here.”);

    }

}

class Z extends Y {

    void method2() {

        System.out.println(“Method2 implemented here.”);

    }

}

What will be the output of the following program?

interface MyFirstInterface {

    void output();

}

interface MySecondInterface extends MyFirstInterface {

    void output();

}

public class DemoOnInterface implements MySecondInterface {

    public void output() {

        System.out.println(“Programming competattion on Payilagam… Hurry up”);

    }

    public static void main(String args[]) {

        DemoOnInterface demoOnInterface = new DemoOnInterface();

        demoOnInterface.output();

    }

}

What will be the output of the following program?

public class CricketPlayersUsingInterfaces {

    public static void main(String s[]) {

        StrongBatsmen sachin = new StrongBatsmen(“Sachin”, 100, 326);

        sachin.makeCentury();

        sachin.takeWickets();

        StrongBatsmen gambhir = new StrongBatsmen(“Gambhir”, 25);

        gambhir.makeCentury();

    }

}

class StrongBatsmen implements IBatsmen, IBowler {

    int numberOfCenturies;

    String name;

    int wickets;

    StrongBatsmen(String name, int numberOfCenturies, int wickets) {

        this.numberOfCenturies = numberOfCenturies;

        this.wickets = wickets;

        this.name = name;

    }

    StrongBatsmen(String name, int numberOfCenturies) {

        this.numberOfCenturies = numberOfCenturies;

        this.name = name;

    }

    public void makeCentury() {

        System.out.println(name + ” made ” + numberOfCenturies + ” centuries.”);

    }

    public void takeWickets() {

        System.out.println(name + ” taken ” + wickets + ” wickets.”);

    }

}

interface IBatsmen {

    void makeCentury();

}

interface IBowler {

    void takeWickets();

}

What will be the output of the following program?

class Company

{

    public static void main(String args[])

    {

        Software.NestedIF nif = new Project();

 

        if(nif.isNotNegative(10))

            System.out.println(“10 is not negative”);

        if(nif.isNotNegative(-12))

            System.out.println(“This won’t be displayed”);

    }

}

 

class Software

{

    public interface NestedIF

    {

        boolean isNotNegative(int x);

    }

}

 

class Project implements Software.NestedIF

{

    public boolean isNotNegative(int x)

    {

        return x < 0 ? false : true;

    }

}

 

 

What will be the output of the following program?

public class King {

    public static void main(String[] args) {

        King k = new King();

        Elephant e = k.new Elephant();

        System.out.print(“Output = “);

        System.out.print(e.step2(2, 3));

    }

    interface Queen {

        float step2(int low, int high);

    }

    interface Pawn {

        float step3(int a, int b, int c);

    }

    abstract class Knight implements Queen, Pawn {

    }

    class Elephant implements Queen {

        public float step2(int x, int y) {

            return 2;

        }

    }

}

What will be the output of the following program?

interface SixesMachine {

    void hitSixes();

}

abstract class DhoniInTheMaking implements SixesMachine {

    public String numberOfSixes() {

        return “6 0 6 3 6 6 6 6”;

    }

    public void printRunsTrail(String runsAndRuns) {

        System.out.println(runsAndRuns);

    }

}

public class Dhoni extends DhoniInTheMaking {

    public static void main(String args[]) {

        DhoniInTheMaking outputClass = new Dhoni();

        outputClass.hitSixes();

    }

    public void hitSixes() {

        numberOfSixes();

        printRunsTrail(numberOfSixes());

    }

}

What will be the output of the following program?

public class King {

    public static void main(String[] args) {

        King k = new King();

        System.out.print(“Output = ” + k.new Elephant().step2(2, 3));

    }

    interface Queen {

        float step2(int low, int high);

    }

    interface Pawn {

        float step3(int a, int b, int c);

    }

    abstract class Knight implements Queen, Pawn {

    }

    class Elephant implements Queen {

        public float step2(int x, int y) {

            return (float)(x * 3);

        }

    }

}

What will be the output of the following program?

public class Revolution2020 {

    public static void main(String[] args) {

        Love love = new Love();

        love.aarti();

        Ambition gopal = new Corruption();

        Ambition raghav = new Ambition() {

            public String goal() {

                return “Pen Is Powerful “;

            }

            public void aarti() {

                System.out.print(“Respect “);

            }

        };

        gopal.aarti(); gopal.goal();

        raghav.aarti(); raghav.goal();

        System.out.print(((Corruption) gopal).shukla());

    }

}

class Love {

    void aarti() { System.out.print(“Beautiful “);    }

}

interface Ambition {

    String goal();

    void aarti();

}

class Corruption extends Love implements Ambition {

    int shukla() throws Exception { return 2020; }

    public String goal() { return “Get Rich “; }

    public void aarti() { System.out.print(“Confused “); }

}

 

What will be the output of the following program?

interface Pet

{

    public void test();

}

class Animal implements Pet

{

    public void test()

    {

        System.out.println(“Interface Method Implemented”);

        System.out.println(“rest of the code”);

    }

    public static void main(String args[])

    {

        Pet p = new Animal();

        p.test();

    }

}

What will be the output of the following program?

public class SmileyTest {

    public static void main(String[] args) {

        Smile a = new Smile();

        talk(a);

        a.frown();

    }

    public static void talk(ISmile ia1) {

        System.out.print(” :-0 “);

        ia1.smile();

    }

}

 

interface ISmile {

    void smile();

}

 

class Smile implements ISmile {

    void smile() {

        System.out.print(” 🙂 “);

    }

    void frown() {

        ISmile a1 = new Smile();

        a1.smile();

        System.out.print(” :-[ “);

    }

}

 

What will be the output of the following program?

public class SmileyTest

{

    public static void main(String[] args)

    {

        SmileyTest s = new SmileyTest();

        Smile a = new Smile();

        s.talk(a);

        a.smile();

        ISmile a1 = new Smile();

        ((Smile)a1).frown();

    }

 

    void talk(Smile ia1)

    {

        ia1.smile();

        System.out.print(” :-0 “);

    }

}

 

class ISmile

{

    void smile()

    {

        smile();

    }

    ISmile()

    {

        System.out.print(” :-@ “);

    }

}

 

class Smile extends ISmile

{

    void smile()

    {

        System.out.print(” 🙂 “);

    }

    void frown()

    {

        ISmile obj = new Smile();

        System.out.print(” :-[ “);

    }

}

 

 

class Small {

    public Small() {

        System.out.print(“a “);

    }

}

 

class Small2  extends Small {

    public Small2() {

        System.out.print(“b “);

    }

}

 

class Small3 extends Small2 {

    public Small3() {

        System.out.print(“c “);

    }

}

 

public class Test {    

    public static void main(String args[]) {

        new Small3();

    }

}

 

Given the code. What is the result?

class Hotel {

    public int bookings;

    public void book() {

        bookings++;

    }

}

 

public class SuperHotel extends Hotel {

    public void book() {

        bookings–;

    }

    public void book(int size) {

        book();

        super.book();

        bookings += size;

    }

 

    public static void main(String args[]) {

        Hotel hotel = new SuperHotel();

        hotel.book(2);

        System.out.print(hotel.bookings);

    }

}

______________________________________________________________________

REFERENCES :
https://payilagam.com/blogs/java-training-in-chennai-basics-learning-part-i/

https://payilagam.com/blogs/java-training-in-chennai-basics-learning-part-ii/ 

https://payilagam.com/blogs/java-training-in-chennai-basics-learning-part-iii/

Java Training in Chennai – Basics – Learning – Part – II

 

 COURTESY :

                         www.proprofs.com, meritcampus.com, www.geeksforgeeks.org,     

                          www.f5java.com, dzone.com, www.examveda.com, beingzero.in/,   

                          scjptest.com,www.gocertify.com, web.cs.iastate.edu,

                          www.sanfoundry.com, https://codingpuzzles.com