Thứ Tư, 20 tháng 4, 2016

Interface trong class

Cần chú ý rằng interface khi khai báo trong class thì có thể là default, public, private, protected. Không giống khi ta khai báo 1 interface độc lập thì chỉ có thể là public


// Java program to demonstrate working of
// interface inside a class.
import java.util.*;
class Test
{
    interface Yes
    {
        void show();
    }
}
 
class Testing implements Test.Yes
{
    public void show()
    {
        System.out.println("show method of interface");
    }
}
 
class A
{
    public static void main(String[] args)
    {
        Test.Yes obj;
        Testing t = new Testing();
        obj=t;
        obj.show();
    }
}

// Java program to demonstrate protected
// specifier for nested interface.
import java.util.*;
class Test
{
    protected interface Yes
    {
        void show();
    }
}
 
class Testing implements Test.Yes
{
    public void show()
    {
        System.out.println("show method of interface");
    }
}
 
class A
{
    public static void main(String[] args)
    {
        Test.Yes obj;
        Testing t = new Testing();
        obj=t;
        obj.show();
    }
}

1 nhận xét:

  1. If you're trying to lose kilograms then you need to get on this totally brand new custom keto meal plan.

    To design this service, licensed nutritionists, fitness trainers, and professional cooks united to develop keto meal plans that are powerful, painless, price-efficient, and delicious.

    From their launch in January 2019, 100's of people have already completely transformed their figure and health with the benefits a certified keto meal plan can give.

    Speaking of benefits; in this link, you'll discover 8 scientifically-proven ones provided by the keto meal plan.

    Trả lờiXóa

Copyright © Dịch từ nguồn geeksforgeeks.org

Distributed By My Blogger Themes | Blogger Theme By NewBloggerThemes Up ↑