❮ Previous Next ❯

Inheritance in java

class Vehicle

   // code
}
class Bike extends Vehicle
{
    // extends the property of Vehicle class
}

Example;
InheritanceExample1.java

package java8s;

class A1
{
      void m1()
      {
            System.out.println("java8s.com");
      }
}

class B extends A1
{
      void m2()
      {
            System.out.println("SILAN TECHNOLOGY");
      }
}

public class InheritanceExample1 {

      public static void main(String[] args) {
           
            //Case-1
            //A1 ob1=new A1();
            //ob1.m1();
            //ob1.m2();
           
            //Case-2  (Best Suitable Case)
            B ob2=new B();
            ob2.m1();
            ob2.m2();
           
            //Case-3
            //A1 ob3=new B();
            //ob3.m1();
            //ob3.m2();
           
            //Case-4
            //B ob4=new A1();    //invalid

      }

}

Output
Inheritance
❮ Previous Next ❯









  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved